cx18-av-core.c 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110
  1. /*
  2. * cx18 ADEC audio functions
  3. *
  4. * Derived from cx25840-core.c
  5. *
  6. * Copyright (C) 2007 Hans Verkuil <hverkuil@xs4all.nl>
  7. * Copyright (C) 2008 Andy Walls <awalls@radix.net>
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version 2
  12. * of the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  22. * 02110-1301, USA.
  23. */
  24. #include "cx18-driver.h"
  25. #include "cx18-io.h"
  26. int cx18_av_write(struct cx18 *cx, u16 addr, u8 value)
  27. {
  28. u32 reg = 0xc40000 + (addr & ~3);
  29. u32 mask = 0xff;
  30. int shift = (addr & 3) * 8;
  31. u32 x = cx18_read_reg(cx, reg);
  32. x = (x & ~(mask << shift)) | ((u32)value << shift);
  33. cx18_write_reg(cx, x, reg);
  34. return 0;
  35. }
  36. int cx18_av_write_expect(struct cx18 *cx, u16 addr, u8 value, u8 eval, u8 mask)
  37. {
  38. u32 reg = 0xc40000 + (addr & ~3);
  39. int shift = (addr & 3) * 8;
  40. u32 x = cx18_read_reg(cx, reg);
  41. x = (x & ~((u32)0xff << shift)) | ((u32)value << shift);
  42. cx18_write_reg_expect(cx, x, reg,
  43. ((u32)eval << shift), ((u32)mask << shift));
  44. return 0;
  45. }
  46. int cx18_av_write4(struct cx18 *cx, u16 addr, u32 value)
  47. {
  48. cx18_write_reg(cx, value, 0xc40000 + addr);
  49. return 0;
  50. }
  51. int
  52. cx18_av_write4_expect(struct cx18 *cx, u16 addr, u32 value, u32 eval, u32 mask)
  53. {
  54. cx18_write_reg_expect(cx, value, 0xc40000 + addr, eval, mask);
  55. return 0;
  56. }
  57. int cx18_av_write4_noretry(struct cx18 *cx, u16 addr, u32 value)
  58. {
  59. cx18_write_reg_noretry(cx, value, 0xc40000 + addr);
  60. return 0;
  61. }
  62. u8 cx18_av_read(struct cx18 *cx, u16 addr)
  63. {
  64. u32 x = cx18_read_reg(cx, 0xc40000 + (addr & ~3));
  65. int shift = (addr & 3) * 8;
  66. return (x >> shift) & 0xff;
  67. }
  68. u32 cx18_av_read4(struct cx18 *cx, u16 addr)
  69. {
  70. return cx18_read_reg(cx, 0xc40000 + addr);
  71. }
  72. int cx18_av_and_or(struct cx18 *cx, u16 addr, unsigned and_mask,
  73. u8 or_value)
  74. {
  75. return cx18_av_write(cx, addr,
  76. (cx18_av_read(cx, addr) & and_mask) |
  77. or_value);
  78. }
  79. int cx18_av_and_or4(struct cx18 *cx, u16 addr, u32 and_mask,
  80. u32 or_value)
  81. {
  82. return cx18_av_write4(cx, addr,
  83. (cx18_av_read4(cx, addr) & and_mask) |
  84. or_value);
  85. }
  86. /* ----------------------------------------------------------------------- */
  87. static int set_input(struct cx18 *cx, enum cx18_av_video_input vid_input,
  88. enum cx18_av_audio_input aud_input);
  89. static void log_audio_status(struct cx18 *cx);
  90. static void log_video_status(struct cx18 *cx);
  91. /* ----------------------------------------------------------------------- */
  92. static void cx18_av_initialize(struct cx18 *cx)
  93. {
  94. struct cx18_av_state *state = &cx->av_state;
  95. u32 v;
  96. cx18_av_loadfw(cx);
  97. /* Stop 8051 code execution */
  98. cx18_av_write4_expect(cx, CXADEC_DL_CTL, 0x03000000,
  99. 0x03000000, 0x13000000);
  100. /* initallize the PLL by toggling sleep bit */
  101. v = cx18_av_read4(cx, CXADEC_HOST_REG1);
  102. /* enable sleep mode - register appears to be read only... */
  103. cx18_av_write4_expect(cx, CXADEC_HOST_REG1, v | 1, v, 0xfffe);
  104. /* disable sleep mode */
  105. cx18_av_write4_expect(cx, CXADEC_HOST_REG1, v & 0xfffe,
  106. v & 0xfffe, 0xffff);
  107. /* initialize DLLs */
  108. v = cx18_av_read4(cx, CXADEC_DLL1_DIAG_CTRL) & 0xE1FFFEFF;
  109. /* disable FLD */
  110. cx18_av_write4(cx, CXADEC_DLL1_DIAG_CTRL, v);
  111. /* enable FLD */
  112. cx18_av_write4(cx, CXADEC_DLL1_DIAG_CTRL, v | 0x10000100);
  113. v = cx18_av_read4(cx, CXADEC_DLL2_DIAG_CTRL) & 0xE1FFFEFF;
  114. /* disable FLD */
  115. cx18_av_write4(cx, CXADEC_DLL2_DIAG_CTRL, v);
  116. /* enable FLD */
  117. cx18_av_write4(cx, CXADEC_DLL2_DIAG_CTRL, v | 0x06000100);
  118. /* set analog bias currents. Set Vreg to 1.20V. */
  119. cx18_av_write4(cx, CXADEC_AFE_DIAG_CTRL1, 0x000A1802);
  120. v = cx18_av_read4(cx, CXADEC_AFE_DIAG_CTRL3) | 1;
  121. /* enable TUNE_FIL_RST */
  122. cx18_av_write4_expect(cx, CXADEC_AFE_DIAG_CTRL3, v, v, 0x03009F0F);
  123. /* disable TUNE_FIL_RST */
  124. cx18_av_write4_expect(cx, CXADEC_AFE_DIAG_CTRL3,
  125. v & 0xFFFFFFFE, v & 0xFFFFFFFE, 0x03009F0F);
  126. /* enable 656 output */
  127. cx18_av_and_or4(cx, CXADEC_PIN_CTRL1, ~0, 0x040C00);
  128. /* video output drive strength */
  129. cx18_av_and_or4(cx, CXADEC_PIN_CTRL2, ~0, 0x2);
  130. /* reset video */
  131. cx18_av_write4(cx, CXADEC_SOFT_RST_CTRL, 0x8000);
  132. cx18_av_write4(cx, CXADEC_SOFT_RST_CTRL, 0);
  133. /* set video to auto-detect */
  134. /* Clear bits 11-12 to enable slow locking mode. Set autodetect mode */
  135. /* set the comb notch = 1 */
  136. cx18_av_and_or4(cx, CXADEC_MODE_CTRL, 0xFFF7E7F0, 0x02040800);
  137. /* Enable wtw_en in CRUSH_CTRL (Set bit 22) */
  138. /* Enable maj_sel in CRUSH_CTRL (Set bit 20) */
  139. cx18_av_and_or4(cx, CXADEC_CRUSH_CTRL, ~0, 0x00500000);
  140. /* Set VGA_TRACK_RANGE to 0x20 */
  141. cx18_av_and_or4(cx, CXADEC_DFE_CTRL2, 0xFFFF00FF, 0x00002000);
  142. /*
  143. * Initial VBI setup
  144. * VIP-1.1, 10 bit mode, enable Raw, disable sliced,
  145. * don't clamp raw samples when codes are in use, 4 byte user D-words,
  146. * programmed IDID, RP code V bit transition on VBLANK, data during
  147. * blanking intervals
  148. */
  149. cx18_av_write4(cx, CXADEC_OUT_CTRL1, 0x4010252e);
  150. /* Set the video input.
  151. The setting in MODE_CTRL gets lost when we do the above setup */
  152. /* EncSetSignalStd(dwDevNum, pEnc->dwSigStd); */
  153. /* EncSetVideoInput(dwDevNum, pEnc->VidIndSelection); */
  154. v = cx18_av_read4(cx, CXADEC_AFE_CTRL);
  155. v &= 0xFFFBFFFF; /* turn OFF bit 18 for droop_comp_ch1 */
  156. v &= 0xFFFF7FFF; /* turn OFF bit 9 for clamp_sel_ch1 */
  157. v &= 0xFFFFFFFE; /* turn OFF bit 0 for 12db_ch1 */
  158. /* v |= 0x00000001;*/ /* turn ON bit 0 for 12db_ch1 */
  159. cx18_av_write4(cx, CXADEC_AFE_CTRL, v);
  160. /* if(dwEnable && dw3DCombAvailable) { */
  161. /* CxDevWrReg(CXADEC_SRC_COMB_CFG, 0x7728021F); */
  162. /* } else { */
  163. /* CxDevWrReg(CXADEC_SRC_COMB_CFG, 0x6628021F); */
  164. /* } */
  165. cx18_av_write4(cx, CXADEC_SRC_COMB_CFG, 0x6628021F);
  166. state->default_volume = 228 - cx18_av_read(cx, 0x8d4);
  167. state->default_volume = ((state->default_volume / 2) + 23) << 9;
  168. }
  169. /* ----------------------------------------------------------------------- */
  170. void cx18_av_std_setup(struct cx18 *cx)
  171. {
  172. struct cx18_av_state *state = &cx->av_state;
  173. v4l2_std_id std = state->std;
  174. int hblank, hactive, burst, vblank, vactive, sc;
  175. int vblank656, src_decimation;
  176. int luma_lpf, uv_lpf, comb;
  177. u32 pll_int, pll_frac, pll_post;
  178. /* datasheet startup, step 8d */
  179. if (std & ~V4L2_STD_NTSC)
  180. cx18_av_write(cx, 0x49f, 0x11);
  181. else
  182. cx18_av_write(cx, 0x49f, 0x14);
  183. if (std & V4L2_STD_625_50) {
  184. hblank = 132;
  185. hactive = 720;
  186. burst = 93;
  187. vblank = 36;
  188. vactive = 580;
  189. vblank656 = 40;
  190. src_decimation = 0x21f;
  191. luma_lpf = 2;
  192. if (std & V4L2_STD_PAL) {
  193. uv_lpf = 1;
  194. comb = 0x20;
  195. sc = 688739;
  196. } else if (std == V4L2_STD_PAL_Nc) {
  197. uv_lpf = 1;
  198. comb = 0x20;
  199. sc = 556453;
  200. } else { /* SECAM */
  201. uv_lpf = 0;
  202. comb = 0;
  203. sc = 672351;
  204. }
  205. } else {
  206. hactive = 720;
  207. hblank = 122;
  208. vactive = 487;
  209. luma_lpf = 1;
  210. uv_lpf = 1;
  211. vblank = 26;
  212. vblank656 = 26;
  213. src_decimation = 0x21f;
  214. if (std == V4L2_STD_PAL_60) {
  215. burst = 0x5b;
  216. luma_lpf = 2;
  217. comb = 0x20;
  218. sc = 688739;
  219. } else if (std == V4L2_STD_PAL_M) {
  220. burst = 0x61;
  221. comb = 0x20;
  222. sc = 555452;
  223. } else {
  224. burst = 0x5b;
  225. comb = 0x66;
  226. sc = 556063;
  227. }
  228. }
  229. /* DEBUG: Displays configured PLL frequency */
  230. pll_int = cx18_av_read(cx, 0x108);
  231. pll_frac = cx18_av_read4(cx, 0x10c) & 0x1ffffff;
  232. pll_post = cx18_av_read(cx, 0x109);
  233. CX18_DEBUG_INFO("PLL regs = int: %u, frac: %u, post: %u\n",
  234. pll_int, pll_frac, pll_post);
  235. if (pll_post) {
  236. int fin, fsc, pll;
  237. pll = (28636360L * ((((u64)pll_int) << 25) + pll_frac)) >> 25;
  238. pll /= pll_post;
  239. CX18_DEBUG_INFO("PLL = %d.%06d MHz\n",
  240. pll / 1000000, pll % 1000000);
  241. CX18_DEBUG_INFO("PLL/8 = %d.%06d MHz\n",
  242. pll / 8000000, (pll / 8) % 1000000);
  243. fin = ((u64)src_decimation * pll) >> 12;
  244. CX18_DEBUG_INFO("ADC Sampling freq = %d.%06d MHz\n",
  245. fin / 1000000, fin % 1000000);
  246. fsc = (((u64)sc) * pll) >> 24L;
  247. CX18_DEBUG_INFO("Chroma sub-carrier freq = %d.%06d MHz\n",
  248. fsc / 1000000, fsc % 1000000);
  249. CX18_DEBUG_INFO("hblank %i, hactive %i, "
  250. "vblank %i , vactive %i, vblank656 %i, src_dec %i,"
  251. "burst 0x%02x, luma_lpf %i, uv_lpf %i, comb 0x%02x,"
  252. " sc 0x%06x\n",
  253. hblank, hactive, vblank, vactive, vblank656,
  254. src_decimation, burst, luma_lpf, uv_lpf, comb, sc);
  255. }
  256. /* Sets horizontal blanking delay and active lines */
  257. cx18_av_write(cx, 0x470, hblank);
  258. cx18_av_write(cx, 0x471, 0xff & (((hblank >> 8) & 0x3) |
  259. (hactive << 4)));
  260. cx18_av_write(cx, 0x472, hactive >> 4);
  261. /* Sets burst gate delay */
  262. cx18_av_write(cx, 0x473, burst);
  263. /* Sets vertical blanking delay and active duration */
  264. cx18_av_write(cx, 0x474, vblank);
  265. cx18_av_write(cx, 0x475, 0xff & (((vblank >> 8) & 0x3) |
  266. (vactive << 4)));
  267. cx18_av_write(cx, 0x476, vactive >> 4);
  268. cx18_av_write(cx, 0x477, vblank656);
  269. /* Sets src decimation rate */
  270. cx18_av_write(cx, 0x478, 0xff & src_decimation);
  271. cx18_av_write(cx, 0x479, 0xff & (src_decimation >> 8));
  272. /* Sets Luma and UV Low pass filters */
  273. cx18_av_write(cx, 0x47a, luma_lpf << 6 | ((uv_lpf << 4) & 0x30));
  274. /* Enables comb filters */
  275. cx18_av_write(cx, 0x47b, comb);
  276. /* Sets SC Step*/
  277. cx18_av_write(cx, 0x47c, sc);
  278. cx18_av_write(cx, 0x47d, 0xff & sc >> 8);
  279. cx18_av_write(cx, 0x47e, 0xff & sc >> 16);
  280. /* Sets VBI parameters */
  281. if (std & V4L2_STD_625_50) {
  282. cx18_av_write(cx, 0x47f, 0x01);
  283. state->vbi_line_offset = 5;
  284. } else {
  285. cx18_av_write(cx, 0x47f, 0x00);
  286. state->vbi_line_offset = 8;
  287. }
  288. }
  289. /* ----------------------------------------------------------------------- */
  290. static void input_change(struct cx18 *cx)
  291. {
  292. struct cx18_av_state *state = &cx->av_state;
  293. v4l2_std_id std = state->std;
  294. u8 v;
  295. /* Follow step 8c and 8d of section 3.16 in the cx18_av datasheet */
  296. cx18_av_write(cx, 0x49f, (std & V4L2_STD_NTSC) ? 0x14 : 0x11);
  297. cx18_av_and_or(cx, 0x401, ~0x60, 0);
  298. cx18_av_and_or(cx, 0x401, ~0x60, 0x60);
  299. if (std & V4L2_STD_525_60) {
  300. if (std == V4L2_STD_NTSC_M_JP) {
  301. /* Japan uses EIAJ audio standard */
  302. cx18_av_write_expect(cx, 0x808, 0xf7, 0xf7, 0xff);
  303. cx18_av_write_expect(cx, 0x80b, 0x02, 0x02, 0x3f);
  304. } else if (std == V4L2_STD_NTSC_M_KR) {
  305. /* South Korea uses A2 audio standard */
  306. cx18_av_write_expect(cx, 0x808, 0xf8, 0xf8, 0xff);
  307. cx18_av_write_expect(cx, 0x80b, 0x03, 0x03, 0x3f);
  308. } else {
  309. /* Others use the BTSC audio standard */
  310. cx18_av_write_expect(cx, 0x808, 0xf6, 0xf6, 0xff);
  311. cx18_av_write_expect(cx, 0x80b, 0x01, 0x01, 0x3f);
  312. }
  313. } else if (std & V4L2_STD_PAL) {
  314. /* Follow tuner change procedure for PAL */
  315. cx18_av_write_expect(cx, 0x808, 0xff, 0xff, 0xff);
  316. cx18_av_write_expect(cx, 0x80b, 0x03, 0x03, 0x3f);
  317. } else if (std & V4L2_STD_SECAM) {
  318. /* Select autodetect for SECAM */
  319. cx18_av_write_expect(cx, 0x808, 0xff, 0xff, 0xff);
  320. cx18_av_write_expect(cx, 0x80b, 0x03, 0x03, 0x3f);
  321. }
  322. v = cx18_av_read(cx, 0x803);
  323. if (v & 0x10) {
  324. /* restart audio decoder microcontroller */
  325. v &= ~0x10;
  326. cx18_av_write_expect(cx, 0x803, v, v, 0x1f);
  327. v |= 0x10;
  328. cx18_av_write_expect(cx, 0x803, v, v, 0x1f);
  329. }
  330. }
  331. static int set_input(struct cx18 *cx, enum cx18_av_video_input vid_input,
  332. enum cx18_av_audio_input aud_input)
  333. {
  334. struct cx18_av_state *state = &cx->av_state;
  335. u8 is_composite = (vid_input >= CX18_AV_COMPOSITE1 &&
  336. vid_input <= CX18_AV_COMPOSITE8);
  337. u8 reg;
  338. u8 v;
  339. CX18_DEBUG_INFO("decoder set video input %d, audio input %d\n",
  340. vid_input, aud_input);
  341. if (is_composite) {
  342. reg = 0xf0 + (vid_input - CX18_AV_COMPOSITE1);
  343. } else {
  344. int luma = vid_input & 0xf0;
  345. int chroma = vid_input & 0xf00;
  346. if ((vid_input & ~0xff0) ||
  347. luma < CX18_AV_SVIDEO_LUMA1 ||
  348. luma > CX18_AV_SVIDEO_LUMA8 ||
  349. chroma < CX18_AV_SVIDEO_CHROMA4 ||
  350. chroma > CX18_AV_SVIDEO_CHROMA8) {
  351. CX18_ERR("0x%04x is not a valid video input!\n",
  352. vid_input);
  353. return -EINVAL;
  354. }
  355. reg = 0xf0 + ((luma - CX18_AV_SVIDEO_LUMA1) >> 4);
  356. if (chroma >= CX18_AV_SVIDEO_CHROMA7) {
  357. reg &= 0x3f;
  358. reg |= (chroma - CX18_AV_SVIDEO_CHROMA7) >> 2;
  359. } else {
  360. reg &= 0xcf;
  361. reg |= (chroma - CX18_AV_SVIDEO_CHROMA4) >> 4;
  362. }
  363. }
  364. switch (aud_input) {
  365. case CX18_AV_AUDIO_SERIAL1:
  366. case CX18_AV_AUDIO_SERIAL2:
  367. /* do nothing, use serial audio input */
  368. break;
  369. case CX18_AV_AUDIO4: reg &= ~0x30; break;
  370. case CX18_AV_AUDIO5: reg &= ~0x30; reg |= 0x10; break;
  371. case CX18_AV_AUDIO6: reg &= ~0x30; reg |= 0x20; break;
  372. case CX18_AV_AUDIO7: reg &= ~0xc0; break;
  373. case CX18_AV_AUDIO8: reg &= ~0xc0; reg |= 0x40; break;
  374. default:
  375. CX18_ERR("0x%04x is not a valid audio input!\n", aud_input);
  376. return -EINVAL;
  377. }
  378. cx18_av_write_expect(cx, 0x103, reg, reg, 0xf7);
  379. /* Set INPUT_MODE to Composite (0) or S-Video (1) */
  380. cx18_av_and_or(cx, 0x401, ~0x6, is_composite ? 0 : 0x02);
  381. /* Set CH_SEL_ADC2 to 1 if input comes from CH3 */
  382. v = cx18_av_read(cx, 0x102);
  383. if (reg & 0x80)
  384. v &= ~0x2;
  385. else
  386. v |= 0x2;
  387. /* Set DUAL_MODE_ADC2 to 1 if input comes from both CH2 and CH3 */
  388. if ((reg & 0xc0) != 0xc0 && (reg & 0x30) != 0x30)
  389. v |= 0x4;
  390. else
  391. v &= ~0x4;
  392. cx18_av_write_expect(cx, 0x102, v, v, 0x17);
  393. /*cx18_av_and_or4(cx, 0x104, ~0x001b4180, 0x00004180);*/
  394. state->vid_input = vid_input;
  395. state->aud_input = aud_input;
  396. cx18_av_audio_set_path(cx);
  397. input_change(cx);
  398. return 0;
  399. }
  400. /* ----------------------------------------------------------------------- */
  401. static int set_v4lstd(struct cx18 *cx)
  402. {
  403. struct cx18_av_state *state = &cx->av_state;
  404. u8 fmt = 0; /* zero is autodetect */
  405. u8 pal_m = 0;
  406. /* First tests should be against specific std */
  407. if (state->std == V4L2_STD_NTSC_M_JP) {
  408. fmt = 0x2;
  409. } else if (state->std == V4L2_STD_NTSC_443) {
  410. fmt = 0x3;
  411. } else if (state->std == V4L2_STD_PAL_M) {
  412. pal_m = 1;
  413. fmt = 0x5;
  414. } else if (state->std == V4L2_STD_PAL_N) {
  415. fmt = 0x6;
  416. } else if (state->std == V4L2_STD_PAL_Nc) {
  417. fmt = 0x7;
  418. } else if (state->std == V4L2_STD_PAL_60) {
  419. fmt = 0x8;
  420. } else {
  421. /* Then, test against generic ones */
  422. if (state->std & V4L2_STD_NTSC)
  423. fmt = 0x1;
  424. else if (state->std & V4L2_STD_PAL)
  425. fmt = 0x4;
  426. else if (state->std & V4L2_STD_SECAM)
  427. fmt = 0xc;
  428. }
  429. CX18_DEBUG_INFO("changing video std to fmt %i\n", fmt);
  430. /* Follow step 9 of section 3.16 in the cx18_av datasheet.
  431. Without this PAL may display a vertical ghosting effect.
  432. This happens for example with the Yuan MPC622. */
  433. if (fmt >= 4 && fmt < 8) {
  434. /* Set format to NTSC-M */
  435. cx18_av_and_or(cx, 0x400, ~0xf, 1);
  436. /* Turn off LCOMB */
  437. cx18_av_and_or(cx, 0x47b, ~6, 0);
  438. }
  439. cx18_av_and_or(cx, 0x400, ~0x2f, fmt | 0x20);
  440. cx18_av_and_or(cx, 0x403, ~0x3, pal_m);
  441. cx18_av_std_setup(cx);
  442. input_change(cx);
  443. return 0;
  444. }
  445. /* ----------------------------------------------------------------------- */
  446. static int set_v4lctrl(struct cx18 *cx, struct v4l2_control *ctrl)
  447. {
  448. switch (ctrl->id) {
  449. case V4L2_CID_BRIGHTNESS:
  450. if (ctrl->value < 0 || ctrl->value > 255) {
  451. CX18_ERR("invalid brightness setting %d\n",
  452. ctrl->value);
  453. return -ERANGE;
  454. }
  455. cx18_av_write(cx, 0x414, ctrl->value - 128);
  456. break;
  457. case V4L2_CID_CONTRAST:
  458. if (ctrl->value < 0 || ctrl->value > 127) {
  459. CX18_ERR("invalid contrast setting %d\n",
  460. ctrl->value);
  461. return -ERANGE;
  462. }
  463. cx18_av_write(cx, 0x415, ctrl->value << 1);
  464. break;
  465. case V4L2_CID_SATURATION:
  466. if (ctrl->value < 0 || ctrl->value > 127) {
  467. CX18_ERR("invalid saturation setting %d\n",
  468. ctrl->value);
  469. return -ERANGE;
  470. }
  471. cx18_av_write(cx, 0x420, ctrl->value << 1);
  472. cx18_av_write(cx, 0x421, ctrl->value << 1);
  473. break;
  474. case V4L2_CID_HUE:
  475. if (ctrl->value < -128 || ctrl->value > 127) {
  476. CX18_ERR("invalid hue setting %d\n", ctrl->value);
  477. return -ERANGE;
  478. }
  479. cx18_av_write(cx, 0x422, ctrl->value);
  480. break;
  481. case V4L2_CID_AUDIO_VOLUME:
  482. case V4L2_CID_AUDIO_BASS:
  483. case V4L2_CID_AUDIO_TREBLE:
  484. case V4L2_CID_AUDIO_BALANCE:
  485. case V4L2_CID_AUDIO_MUTE:
  486. return cx18_av_audio(cx, VIDIOC_S_CTRL, ctrl);
  487. default:
  488. return -EINVAL;
  489. }
  490. return 0;
  491. }
  492. static int get_v4lctrl(struct cx18 *cx, struct v4l2_control *ctrl)
  493. {
  494. switch (ctrl->id) {
  495. case V4L2_CID_BRIGHTNESS:
  496. ctrl->value = (s8)cx18_av_read(cx, 0x414) + 128;
  497. break;
  498. case V4L2_CID_CONTRAST:
  499. ctrl->value = cx18_av_read(cx, 0x415) >> 1;
  500. break;
  501. case V4L2_CID_SATURATION:
  502. ctrl->value = cx18_av_read(cx, 0x420) >> 1;
  503. break;
  504. case V4L2_CID_HUE:
  505. ctrl->value = (s8)cx18_av_read(cx, 0x422);
  506. break;
  507. case V4L2_CID_AUDIO_VOLUME:
  508. case V4L2_CID_AUDIO_BASS:
  509. case V4L2_CID_AUDIO_TREBLE:
  510. case V4L2_CID_AUDIO_BALANCE:
  511. case V4L2_CID_AUDIO_MUTE:
  512. return cx18_av_audio(cx, VIDIOC_G_CTRL, ctrl);
  513. default:
  514. return -EINVAL;
  515. }
  516. return 0;
  517. }
  518. /* ----------------------------------------------------------------------- */
  519. static int get_v4lfmt(struct cx18 *cx, struct v4l2_format *fmt)
  520. {
  521. switch (fmt->type) {
  522. case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
  523. return cx18_av_vbi(cx, VIDIOC_G_FMT, fmt);
  524. default:
  525. return -EINVAL;
  526. }
  527. return 0;
  528. }
  529. static int set_v4lfmt(struct cx18 *cx, struct v4l2_format *fmt)
  530. {
  531. struct cx18_av_state *state = &cx->av_state;
  532. struct v4l2_pix_format *pix;
  533. int HSC, VSC, Vsrc, Hsrc, filter, Vlines;
  534. int is_50Hz = !(state->std & V4L2_STD_525_60);
  535. switch (fmt->type) {
  536. case V4L2_BUF_TYPE_VIDEO_CAPTURE:
  537. pix = &(fmt->fmt.pix);
  538. Vsrc = (cx18_av_read(cx, 0x476) & 0x3f) << 4;
  539. Vsrc |= (cx18_av_read(cx, 0x475) & 0xf0) >> 4;
  540. Hsrc = (cx18_av_read(cx, 0x472) & 0x3f) << 4;
  541. Hsrc |= (cx18_av_read(cx, 0x471) & 0xf0) >> 4;
  542. Vlines = pix->height + (is_50Hz ? 4 : 7);
  543. if ((pix->width * 16 < Hsrc) || (Hsrc < pix->width) ||
  544. (Vlines * 8 < Vsrc) || (Vsrc < Vlines)) {
  545. CX18_ERR("%dx%d is not a valid size!\n",
  546. pix->width, pix->height);
  547. return -ERANGE;
  548. }
  549. HSC = (Hsrc * (1 << 20)) / pix->width - (1 << 20);
  550. VSC = (1 << 16) - (Vsrc * (1 << 9) / Vlines - (1 << 9));
  551. VSC &= 0x1fff;
  552. if (pix->width >= 385)
  553. filter = 0;
  554. else if (pix->width > 192)
  555. filter = 1;
  556. else if (pix->width > 96)
  557. filter = 2;
  558. else
  559. filter = 3;
  560. CX18_DEBUG_INFO("decoder set size %dx%d -> scale %ux%u\n",
  561. pix->width, pix->height, HSC, VSC);
  562. /* HSCALE=HSC */
  563. cx18_av_write(cx, 0x418, HSC & 0xff);
  564. cx18_av_write(cx, 0x419, (HSC >> 8) & 0xff);
  565. cx18_av_write(cx, 0x41a, HSC >> 16);
  566. /* VSCALE=VSC */
  567. cx18_av_write(cx, 0x41c, VSC & 0xff);
  568. cx18_av_write(cx, 0x41d, VSC >> 8);
  569. /* VS_INTRLACE=1 VFILT=filter */
  570. cx18_av_write(cx, 0x41e, 0x8 | filter);
  571. break;
  572. case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
  573. return cx18_av_vbi(cx, VIDIOC_S_FMT, fmt);
  574. case V4L2_BUF_TYPE_VBI_CAPTURE:
  575. return cx18_av_vbi(cx, VIDIOC_S_FMT, fmt);
  576. default:
  577. return -EINVAL;
  578. }
  579. return 0;
  580. }
  581. /* ----------------------------------------------------------------------- */
  582. static int valid_av_cmd(unsigned int cmd)
  583. {
  584. switch (cmd) {
  585. /* All commands supported by cx18_av_cmd() */
  586. case VIDIOC_INT_DECODE_VBI_LINE:
  587. case VIDIOC_INT_AUDIO_CLOCK_FREQ:
  588. case VIDIOC_STREAMON:
  589. case VIDIOC_STREAMOFF:
  590. case VIDIOC_LOG_STATUS:
  591. case VIDIOC_G_CTRL:
  592. case VIDIOC_S_CTRL:
  593. case VIDIOC_QUERYCTRL:
  594. case VIDIOC_G_STD:
  595. case VIDIOC_S_STD:
  596. case AUDC_SET_RADIO:
  597. case VIDIOC_INT_G_VIDEO_ROUTING:
  598. case VIDIOC_INT_S_VIDEO_ROUTING:
  599. case VIDIOC_INT_G_AUDIO_ROUTING:
  600. case VIDIOC_INT_S_AUDIO_ROUTING:
  601. case VIDIOC_S_FREQUENCY:
  602. case VIDIOC_G_TUNER:
  603. case VIDIOC_S_TUNER:
  604. case VIDIOC_G_FMT:
  605. case VIDIOC_S_FMT:
  606. case VIDIOC_INT_RESET:
  607. return 1;
  608. default:
  609. return 0;
  610. }
  611. return 0;
  612. }
  613. int cx18_av_cmd(struct cx18 *cx, unsigned int cmd, void *arg)
  614. {
  615. struct cx18_av_state *state = &cx->av_state;
  616. struct v4l2_tuner *vt = arg;
  617. struct v4l2_routing *route = arg;
  618. if (!state->is_initialized && valid_av_cmd(cmd)) {
  619. CX18_DEBUG_INFO("cmd %08x triggered fw load\n", cmd);
  620. /* initialize on first use */
  621. state->is_initialized = 1;
  622. cx18_av_initialize(cx);
  623. }
  624. switch (cmd) {
  625. case VIDIOC_INT_DECODE_VBI_LINE:
  626. return cx18_av_vbi(cx, cmd, arg);
  627. case VIDIOC_INT_AUDIO_CLOCK_FREQ:
  628. return cx18_av_audio(cx, cmd, arg);
  629. case VIDIOC_STREAMON:
  630. CX18_DEBUG_INFO("enable output\n");
  631. cx18_av_write(cx, 0x115, 0x8c);
  632. cx18_av_write(cx, 0x116, 0x07);
  633. break;
  634. case VIDIOC_STREAMOFF:
  635. CX18_DEBUG_INFO("disable output\n");
  636. cx18_av_write(cx, 0x115, 0x00);
  637. cx18_av_write(cx, 0x116, 0x00);
  638. break;
  639. case VIDIOC_LOG_STATUS:
  640. log_video_status(cx);
  641. log_audio_status(cx);
  642. break;
  643. case VIDIOC_G_CTRL:
  644. return get_v4lctrl(cx, (struct v4l2_control *)arg);
  645. case VIDIOC_S_CTRL:
  646. return set_v4lctrl(cx, (struct v4l2_control *)arg);
  647. case VIDIOC_QUERYCTRL:
  648. {
  649. struct v4l2_queryctrl *qc = arg;
  650. switch (qc->id) {
  651. case V4L2_CID_BRIGHTNESS:
  652. case V4L2_CID_CONTRAST:
  653. case V4L2_CID_SATURATION:
  654. case V4L2_CID_HUE:
  655. return v4l2_ctrl_query_fill_std(qc);
  656. default:
  657. break;
  658. }
  659. switch (qc->id) {
  660. case V4L2_CID_AUDIO_VOLUME:
  661. return v4l2_ctrl_query_fill(qc, 0, 65535,
  662. 65535 / 100, state->default_volume);
  663. case V4L2_CID_AUDIO_MUTE:
  664. case V4L2_CID_AUDIO_BALANCE:
  665. case V4L2_CID_AUDIO_BASS:
  666. case V4L2_CID_AUDIO_TREBLE:
  667. return v4l2_ctrl_query_fill_std(qc);
  668. default:
  669. return -EINVAL;
  670. }
  671. return -EINVAL;
  672. }
  673. case VIDIOC_G_STD:
  674. *(v4l2_std_id *)arg = state->std;
  675. break;
  676. case VIDIOC_S_STD:
  677. if (state->radio == 0 && state->std == *(v4l2_std_id *)arg)
  678. return 0;
  679. state->radio = 0;
  680. state->std = *(v4l2_std_id *)arg;
  681. return set_v4lstd(cx);
  682. case AUDC_SET_RADIO:
  683. state->radio = 1;
  684. break;
  685. case VIDIOC_INT_G_VIDEO_ROUTING:
  686. route->input = state->vid_input;
  687. route->output = 0;
  688. break;
  689. case VIDIOC_INT_S_VIDEO_ROUTING:
  690. return set_input(cx, route->input, state->aud_input);
  691. case VIDIOC_INT_G_AUDIO_ROUTING:
  692. route->input = state->aud_input;
  693. route->output = 0;
  694. break;
  695. case VIDIOC_INT_S_AUDIO_ROUTING:
  696. return set_input(cx, state->vid_input, route->input);
  697. case VIDIOC_S_FREQUENCY:
  698. input_change(cx);
  699. break;
  700. case VIDIOC_G_TUNER:
  701. {
  702. u8 vpres = cx18_av_read(cx, 0x40e) & 0x20;
  703. u8 mode;
  704. int val = 0;
  705. if (state->radio)
  706. break;
  707. vt->signal = vpres ? 0xffff : 0x0;
  708. vt->capability |=
  709. V4L2_TUNER_CAP_STEREO | V4L2_TUNER_CAP_LANG1 |
  710. V4L2_TUNER_CAP_LANG2 | V4L2_TUNER_CAP_SAP;
  711. mode = cx18_av_read(cx, 0x804);
  712. /* get rxsubchans and audmode */
  713. if ((mode & 0xf) == 1)
  714. val |= V4L2_TUNER_SUB_STEREO;
  715. else
  716. val |= V4L2_TUNER_SUB_MONO;
  717. if (mode == 2 || mode == 4)
  718. val = V4L2_TUNER_SUB_LANG1 | V4L2_TUNER_SUB_LANG2;
  719. if (mode & 0x10)
  720. val |= V4L2_TUNER_SUB_SAP;
  721. vt->rxsubchans = val;
  722. vt->audmode = state->audmode;
  723. break;
  724. }
  725. case VIDIOC_S_TUNER:
  726. {
  727. u8 v;
  728. if (state->radio)
  729. break;
  730. v = cx18_av_read(cx, 0x809);
  731. v &= ~0xf;
  732. switch (vt->audmode) {
  733. case V4L2_TUNER_MODE_MONO:
  734. /* mono -> mono
  735. stereo -> mono
  736. bilingual -> lang1 */
  737. break;
  738. case V4L2_TUNER_MODE_STEREO:
  739. case V4L2_TUNER_MODE_LANG1:
  740. /* mono -> mono
  741. stereo -> stereo
  742. bilingual -> lang1 */
  743. v |= 0x4;
  744. break;
  745. case V4L2_TUNER_MODE_LANG1_LANG2:
  746. /* mono -> mono
  747. stereo -> stereo
  748. bilingual -> lang1/lang2 */
  749. v |= 0x7;
  750. break;
  751. case V4L2_TUNER_MODE_LANG2:
  752. /* mono -> mono
  753. stereo -> stereo
  754. bilingual -> lang2 */
  755. v |= 0x1;
  756. break;
  757. default:
  758. return -EINVAL;
  759. }
  760. cx18_av_write_expect(cx, 0x809, v, v, 0xff);
  761. state->audmode = vt->audmode;
  762. break;
  763. }
  764. case VIDIOC_G_FMT:
  765. return get_v4lfmt(cx, (struct v4l2_format *)arg);
  766. case VIDIOC_S_FMT:
  767. return set_v4lfmt(cx, (struct v4l2_format *)arg);
  768. case VIDIOC_INT_RESET:
  769. cx18_av_initialize(cx);
  770. break;
  771. default:
  772. return -EINVAL;
  773. }
  774. return 0;
  775. }
  776. /* ----------------------------------------------------------------------- */
  777. /* ----------------------------------------------------------------------- */
  778. static void log_video_status(struct cx18 *cx)
  779. {
  780. static const char *const fmt_strs[] = {
  781. "0x0",
  782. "NTSC-M", "NTSC-J", "NTSC-4.43",
  783. "PAL-BDGHI", "PAL-M", "PAL-N", "PAL-Nc", "PAL-60",
  784. "0x9", "0xA", "0xB",
  785. "SECAM",
  786. "0xD", "0xE", "0xF"
  787. };
  788. struct cx18_av_state *state = &cx->av_state;
  789. u8 vidfmt_sel = cx18_av_read(cx, 0x400) & 0xf;
  790. u8 gen_stat1 = cx18_av_read(cx, 0x40d);
  791. u8 gen_stat2 = cx18_av_read(cx, 0x40e);
  792. int vid_input = state->vid_input;
  793. CX18_INFO("Video signal: %spresent\n",
  794. (gen_stat2 & 0x20) ? "" : "not ");
  795. CX18_INFO("Detected format: %s\n",
  796. fmt_strs[gen_stat1 & 0xf]);
  797. CX18_INFO("Specified standard: %s\n",
  798. vidfmt_sel ? fmt_strs[vidfmt_sel] : "automatic detection");
  799. if (vid_input >= CX18_AV_COMPOSITE1 &&
  800. vid_input <= CX18_AV_COMPOSITE8) {
  801. CX18_INFO("Specified video input: Composite %d\n",
  802. vid_input - CX18_AV_COMPOSITE1 + 1);
  803. } else {
  804. CX18_INFO("Specified video input: S-Video (Luma In%d, Chroma In%d)\n",
  805. (vid_input & 0xf0) >> 4, (vid_input & 0xf00) >> 8);
  806. }
  807. CX18_INFO("Specified audioclock freq: %d Hz\n", state->audclk_freq);
  808. }
  809. /* ----------------------------------------------------------------------- */
  810. static void log_audio_status(struct cx18 *cx)
  811. {
  812. struct cx18_av_state *state = &cx->av_state;
  813. u8 download_ctl = cx18_av_read(cx, 0x803);
  814. u8 mod_det_stat0 = cx18_av_read(cx, 0x804);
  815. u8 mod_det_stat1 = cx18_av_read(cx, 0x805);
  816. u8 audio_config = cx18_av_read(cx, 0x808);
  817. u8 pref_mode = cx18_av_read(cx, 0x809);
  818. u8 afc0 = cx18_av_read(cx, 0x80b);
  819. u8 mute_ctl = cx18_av_read(cx, 0x8d3);
  820. int aud_input = state->aud_input;
  821. char *p;
  822. switch (mod_det_stat0) {
  823. case 0x00: p = "mono"; break;
  824. case 0x01: p = "stereo"; break;
  825. case 0x02: p = "dual"; break;
  826. case 0x04: p = "tri"; break;
  827. case 0x10: p = "mono with SAP"; break;
  828. case 0x11: p = "stereo with SAP"; break;
  829. case 0x12: p = "dual with SAP"; break;
  830. case 0x14: p = "tri with SAP"; break;
  831. case 0xfe: p = "forced mode"; break;
  832. default: p = "not defined"; break;
  833. }
  834. CX18_INFO("Detected audio mode: %s\n", p);
  835. switch (mod_det_stat1) {
  836. case 0x00: p = "not defined"; break;
  837. case 0x01: p = "EIAJ"; break;
  838. case 0x02: p = "A2-M"; break;
  839. case 0x03: p = "A2-BG"; break;
  840. case 0x04: p = "A2-DK1"; break;
  841. case 0x05: p = "A2-DK2"; break;
  842. case 0x06: p = "A2-DK3"; break;
  843. case 0x07: p = "A1 (6.0 MHz FM Mono)"; break;
  844. case 0x08: p = "AM-L"; break;
  845. case 0x09: p = "NICAM-BG"; break;
  846. case 0x0a: p = "NICAM-DK"; break;
  847. case 0x0b: p = "NICAM-I"; break;
  848. case 0x0c: p = "NICAM-L"; break;
  849. case 0x0d: p = "BTSC/EIAJ/A2-M Mono (4.5 MHz FMMono)"; break;
  850. case 0x0e: p = "IF FM Radio"; break;
  851. case 0x0f: p = "BTSC"; break;
  852. case 0x10: p = "detected chrominance"; break;
  853. case 0xfd: p = "unknown audio standard"; break;
  854. case 0xfe: p = "forced audio standard"; break;
  855. case 0xff: p = "no detected audio standard"; break;
  856. default: p = "not defined"; break;
  857. }
  858. CX18_INFO("Detected audio standard: %s\n", p);
  859. CX18_INFO("Audio muted: %s\n",
  860. (mute_ctl & 0x2) ? "yes" : "no");
  861. CX18_INFO("Audio microcontroller: %s\n",
  862. (download_ctl & 0x10) ? "running" : "stopped");
  863. switch (audio_config >> 4) {
  864. case 0x00: p = "undefined"; break;
  865. case 0x01: p = "BTSC"; break;
  866. case 0x02: p = "EIAJ"; break;
  867. case 0x03: p = "A2-M"; break;
  868. case 0x04: p = "A2-BG"; break;
  869. case 0x05: p = "A2-DK1"; break;
  870. case 0x06: p = "A2-DK2"; break;
  871. case 0x07: p = "A2-DK3"; break;
  872. case 0x08: p = "A1 (6.0 MHz FM Mono)"; break;
  873. case 0x09: p = "AM-L"; break;
  874. case 0x0a: p = "NICAM-BG"; break;
  875. case 0x0b: p = "NICAM-DK"; break;
  876. case 0x0c: p = "NICAM-I"; break;
  877. case 0x0d: p = "NICAM-L"; break;
  878. case 0x0e: p = "FM radio"; break;
  879. case 0x0f: p = "automatic detection"; break;
  880. default: p = "undefined"; break;
  881. }
  882. CX18_INFO("Configured audio standard: %s\n", p);
  883. if ((audio_config >> 4) < 0xF) {
  884. switch (audio_config & 0xF) {
  885. case 0x00: p = "MONO1 (LANGUAGE A/Mono L+R channel for BTSC, EIAJ, A2)"; break;
  886. case 0x01: p = "MONO2 (LANGUAGE B)"; break;
  887. case 0x02: p = "MONO3 (STEREO forced MONO)"; break;
  888. case 0x03: p = "MONO4 (NICAM ANALOG-Language C/Analog Fallback)"; break;
  889. case 0x04: p = "STEREO"; break;
  890. case 0x05: p = "DUAL1 (AC)"; break;
  891. case 0x06: p = "DUAL2 (BC)"; break;
  892. case 0x07: p = "DUAL3 (AB)"; break;
  893. default: p = "undefined";
  894. }
  895. CX18_INFO("Configured audio mode: %s\n", p);
  896. } else {
  897. switch (audio_config & 0xF) {
  898. case 0x00: p = "BG"; break;
  899. case 0x01: p = "DK1"; break;
  900. case 0x02: p = "DK2"; break;
  901. case 0x03: p = "DK3"; break;
  902. case 0x04: p = "I"; break;
  903. case 0x05: p = "L"; break;
  904. case 0x06: p = "BTSC"; break;
  905. case 0x07: p = "EIAJ"; break;
  906. case 0x08: p = "A2-M"; break;
  907. case 0x09: p = "FM Radio (4.5 MHz)"; break;
  908. case 0x0a: p = "FM Radio (5.5 MHz)"; break;
  909. case 0x0b: p = "S-Video"; break;
  910. case 0x0f: p = "automatic standard and mode detection"; break;
  911. default: p = "undefined"; break;
  912. }
  913. CX18_INFO("Configured audio system: %s\n", p);
  914. }
  915. if (aud_input)
  916. CX18_INFO("Specified audio input: Tuner (In%d)\n",
  917. aud_input);
  918. else
  919. CX18_INFO("Specified audio input: External\n");
  920. switch (pref_mode & 0xf) {
  921. case 0: p = "mono/language A"; break;
  922. case 1: p = "language B"; break;
  923. case 2: p = "language C"; break;
  924. case 3: p = "analog fallback"; break;
  925. case 4: p = "stereo"; break;
  926. case 5: p = "language AC"; break;
  927. case 6: p = "language BC"; break;
  928. case 7: p = "language AB"; break;
  929. default: p = "undefined"; break;
  930. }
  931. CX18_INFO("Preferred audio mode: %s\n", p);
  932. if ((audio_config & 0xf) == 0xf) {
  933. switch ((afc0 >> 3) & 0x1) {
  934. case 0: p = "system DK"; break;
  935. case 1: p = "system L"; break;
  936. }
  937. CX18_INFO("Selected 65 MHz format: %s\n", p);
  938. switch (afc0 & 0x7) {
  939. case 0: p = "Chroma"; break;
  940. case 1: p = "BTSC"; break;
  941. case 2: p = "EIAJ"; break;
  942. case 3: p = "A2-M"; break;
  943. case 4: p = "autodetect"; break;
  944. default: p = "undefined"; break;
  945. }
  946. CX18_INFO("Selected 45 MHz format: %s\n", p);
  947. }
  948. }