cx25840-core.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168
  1. /* cx25840 - Conexant CX25840 audio/video decoder driver
  2. *
  3. * Copyright (C) 2004 Ulf Eklund
  4. *
  5. * Based on the saa7115 driver and on the first verison of Chris Kennedy's
  6. * cx25840 driver.
  7. *
  8. * Changes by Tyler Trafford <tatrafford@comcast.net>
  9. * - cleanup/rewrite for V4L2 API (2005)
  10. *
  11. * VBI support by Hans Verkuil <hverkuil@xs4all.nl>.
  12. *
  13. * NTSC sliced VBI support by Christopher Neufeld <television@cneufeld.ca>
  14. * with additional fixes by Hans Verkuil <hverkuil@xs4all.nl>.
  15. *
  16. * This program is free software; you can redistribute it and/or
  17. * modify it under the terms of the GNU General Public License
  18. * as published by the Free Software Foundation; either version 2
  19. * of the License, or (at your option) any later version.
  20. *
  21. * This program is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU General Public License
  27. * along with this program; if not, write to the Free Software
  28. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  29. */
  30. #include <linux/kernel.h>
  31. #include <linux/module.h>
  32. #include <linux/slab.h>
  33. #include <linux/videodev2.h>
  34. #include <linux/i2c.h>
  35. #include <media/v4l2-common.h>
  36. #include <media/v4l2-chip-ident.h>
  37. #include <media/cx25840.h>
  38. #include "cx25840-core.h"
  39. MODULE_DESCRIPTION("Conexant CX25840 audio/video decoder driver");
  40. MODULE_AUTHOR("Ulf Eklund, Chris Kennedy, Hans Verkuil, Tyler Trafford");
  41. MODULE_LICENSE("GPL");
  42. static unsigned short normal_i2c[] = { 0x88 >> 1, I2C_CLIENT_END };
  43. int cx25840_debug;
  44. module_param_named(debug,cx25840_debug, int, 0644);
  45. MODULE_PARM_DESC(debug, "Debugging messages [0=Off (default) 1=On]");
  46. I2C_CLIENT_INSMOD;
  47. /* ----------------------------------------------------------------------- */
  48. int cx25840_write(struct i2c_client *client, u16 addr, u8 value)
  49. {
  50. u8 buffer[3];
  51. buffer[0] = addr >> 8;
  52. buffer[1] = addr & 0xff;
  53. buffer[2] = value;
  54. return i2c_master_send(client, buffer, 3);
  55. }
  56. int cx25840_write4(struct i2c_client *client, u16 addr, u32 value)
  57. {
  58. u8 buffer[6];
  59. buffer[0] = addr >> 8;
  60. buffer[1] = addr & 0xff;
  61. buffer[2] = value >> 24;
  62. buffer[3] = (value >> 16) & 0xff;
  63. buffer[4] = (value >> 8) & 0xff;
  64. buffer[5] = value & 0xff;
  65. return i2c_master_send(client, buffer, 6);
  66. }
  67. u8 cx25840_read(struct i2c_client * client, u16 addr)
  68. {
  69. u8 buffer[2];
  70. buffer[0] = addr >> 8;
  71. buffer[1] = addr & 0xff;
  72. if (i2c_master_send(client, buffer, 2) < 2)
  73. return 0;
  74. if (i2c_master_recv(client, buffer, 1) < 1)
  75. return 0;
  76. return buffer[0];
  77. }
  78. u32 cx25840_read4(struct i2c_client * client, u16 addr)
  79. {
  80. u8 buffer[4];
  81. buffer[0] = addr >> 8;
  82. buffer[1] = addr & 0xff;
  83. if (i2c_master_send(client, buffer, 2) < 2)
  84. return 0;
  85. if (i2c_master_recv(client, buffer, 4) < 4)
  86. return 0;
  87. return (buffer[3] << 24) | (buffer[2] << 16) |
  88. (buffer[1] << 8) | buffer[0];
  89. }
  90. int cx25840_and_or(struct i2c_client *client, u16 addr, unsigned and_mask,
  91. u8 or_value)
  92. {
  93. return cx25840_write(client, addr,
  94. (cx25840_read(client, addr) & and_mask) |
  95. or_value);
  96. }
  97. /* ----------------------------------------------------------------------- */
  98. static int set_input(struct i2c_client *client, enum cx25840_video_input vid_input,
  99. enum cx25840_audio_input aud_input);
  100. static void log_audio_status(struct i2c_client *client);
  101. static void log_video_status(struct i2c_client *client);
  102. /* ----------------------------------------------------------------------- */
  103. static void init_dll1(struct i2c_client *client)
  104. {
  105. /* This is the Hauppauge sequence used to
  106. * initialize the Delay Lock Loop 1 (ADC DLL). */
  107. cx25840_write(client, 0x159, 0x23);
  108. cx25840_write(client, 0x15a, 0x87);
  109. cx25840_write(client, 0x15b, 0x06);
  110. cx25840_write(client, 0x159, 0xe1);
  111. cx25840_write(client, 0x15a, 0x86);
  112. cx25840_write(client, 0x159, 0xe0);
  113. cx25840_write(client, 0x159, 0xe1);
  114. cx25840_write(client, 0x15b, 0x10);
  115. }
  116. static void init_dll2(struct i2c_client *client)
  117. {
  118. /* This is the Hauppauge sequence used to
  119. * initialize the Delay Lock Loop 2 (ADC DLL). */
  120. cx25840_write(client, 0x15d, 0xe3);
  121. cx25840_write(client, 0x15e, 0x86);
  122. cx25840_write(client, 0x15f, 0x06);
  123. cx25840_write(client, 0x15d, 0xe1);
  124. cx25840_write(client, 0x15d, 0xe0);
  125. cx25840_write(client, 0x15d, 0xe1);
  126. }
  127. static void cx25836_initialize(struct i2c_client *client)
  128. {
  129. /* reset configuration is described on page 3-77 of the CX25836 datasheet */
  130. /* 2. */
  131. cx25840_and_or(client, 0x000, ~0x01, 0x01);
  132. cx25840_and_or(client, 0x000, ~0x01, 0x00);
  133. /* 3a. */
  134. cx25840_and_or(client, 0x15a, ~0x70, 0x00);
  135. /* 3b. */
  136. cx25840_and_or(client, 0x15b, ~0x1e, 0x06);
  137. /* 3c. */
  138. cx25840_and_or(client, 0x159, ~0x02, 0x02);
  139. /* 3d. */
  140. /* There should be a 10-us delay here, but since the
  141. i2c bus already has a 10-us delay we don't need to do
  142. anything */
  143. /* 3e. */
  144. cx25840_and_or(client, 0x159, ~0x02, 0x00);
  145. /* 3f. */
  146. cx25840_and_or(client, 0x159, ~0xc0, 0xc0);
  147. /* 3g. */
  148. cx25840_and_or(client, 0x159, ~0x01, 0x00);
  149. cx25840_and_or(client, 0x159, ~0x01, 0x01);
  150. /* 3h. */
  151. cx25840_and_or(client, 0x15b, ~0x1e, 0x10);
  152. }
  153. static void cx25840_initialize(struct i2c_client *client)
  154. {
  155. struct cx25840_state *state = i2c_get_clientdata(client);
  156. /* datasheet startup in numbered steps, refer to page 3-77 */
  157. /* 2. */
  158. cx25840_and_or(client, 0x803, ~0x10, 0x00);
  159. /* The default of this register should be 4, but I get 0 instead.
  160. * Set this register to 4 manually. */
  161. cx25840_write(client, 0x000, 0x04);
  162. /* 3. */
  163. init_dll1(client);
  164. init_dll2(client);
  165. cx25840_write(client, 0x136, 0x0a);
  166. /* 4. */
  167. cx25840_write(client, 0x13c, 0x01);
  168. cx25840_write(client, 0x13c, 0x00);
  169. /* 5. */
  170. cx25840_loadfw(client);
  171. /* 6. */
  172. cx25840_write(client, 0x115, 0x8c);
  173. cx25840_write(client, 0x116, 0x07);
  174. cx25840_write(client, 0x118, 0x02);
  175. /* 7. */
  176. cx25840_write(client, 0x4a5, 0x80);
  177. cx25840_write(client, 0x4a5, 0x00);
  178. cx25840_write(client, 0x402, 0x00);
  179. /* 8. */
  180. cx25840_and_or(client, 0x401, ~0x18, 0);
  181. cx25840_and_or(client, 0x4a2, ~0x10, 0x10);
  182. /* steps 8c and 8d are done in change_input() */
  183. /* 10. */
  184. cx25840_write(client, 0x8d3, 0x1f);
  185. cx25840_write(client, 0x8e3, 0x03);
  186. cx25840_vbi_setup(client);
  187. /* trial and error says these are needed to get audio */
  188. cx25840_write(client, 0x914, 0xa0);
  189. cx25840_write(client, 0x918, 0xa0);
  190. cx25840_write(client, 0x919, 0x01);
  191. /* stereo prefered */
  192. cx25840_write(client, 0x809, 0x04);
  193. /* AC97 shift */
  194. cx25840_write(client, 0x8cf, 0x0f);
  195. /* (re)set input */
  196. set_input(client, state->vid_input, state->aud_input);
  197. /* start microcontroller */
  198. cx25840_and_or(client, 0x803, ~0x10, 0x10);
  199. }
  200. /* ----------------------------------------------------------------------- */
  201. static void input_change(struct i2c_client *client)
  202. {
  203. struct cx25840_state *state = i2c_get_clientdata(client);
  204. v4l2_std_id std = cx25840_get_v4lstd(client);
  205. /* Follow step 8c and 8d of section 3.16 in the cx25840 datasheet */
  206. if (std & V4L2_STD_SECAM) {
  207. cx25840_write(client, 0x402, 0);
  208. }
  209. else {
  210. cx25840_write(client, 0x402, 0x04);
  211. cx25840_write(client, 0x49f, (std & V4L2_STD_NTSC) ? 0x14 : 0x11);
  212. }
  213. cx25840_and_or(client, 0x401, ~0x60, 0);
  214. cx25840_and_or(client, 0x401, ~0x60, 0x60);
  215. if (std & V4L2_STD_525_60) {
  216. /* Certain Hauppauge PVR150 models have a hardware bug
  217. that causes audio to drop out. For these models the
  218. audio standard must be set explicitly.
  219. To be precise: it affects cards with tuner models
  220. 85, 99 and 112 (model numbers from tveeprom). */
  221. int hw_fix = state->pvr150_workaround;
  222. if (std == V4L2_STD_NTSC_M_JP) {
  223. /* Japan uses EIAJ audio standard */
  224. cx25840_write(client, 0x808, hw_fix ? 0x2f : 0xf7);
  225. } else if (std == V4L2_STD_NTSC_M_KR) {
  226. /* South Korea uses A2 audio standard */
  227. cx25840_write(client, 0x808, hw_fix ? 0x3f : 0xf8);
  228. } else {
  229. /* Others use the BTSC audio standard */
  230. cx25840_write(client, 0x808, hw_fix ? 0x1f : 0xf6);
  231. }
  232. cx25840_write(client, 0x80b, 0x00);
  233. } else if (std & V4L2_STD_PAL) {
  234. /* Follow tuner change procedure for PAL */
  235. cx25840_write(client, 0x808, 0xff);
  236. cx25840_write(client, 0x80b, 0x10);
  237. } else if (std & V4L2_STD_SECAM) {
  238. /* Select autodetect for SECAM */
  239. cx25840_write(client, 0x808, 0xff);
  240. cx25840_write(client, 0x80b, 0x10);
  241. }
  242. if (cx25840_read(client, 0x803) & 0x10) {
  243. /* restart audio decoder microcontroller */
  244. cx25840_and_or(client, 0x803, ~0x10, 0x00);
  245. cx25840_and_or(client, 0x803, ~0x10, 0x10);
  246. }
  247. }
  248. static int set_input(struct i2c_client *client, enum cx25840_video_input vid_input,
  249. enum cx25840_audio_input aud_input)
  250. {
  251. struct cx25840_state *state = i2c_get_clientdata(client);
  252. u8 is_composite = (vid_input >= CX25840_COMPOSITE1 &&
  253. vid_input <= CX25840_COMPOSITE8);
  254. u8 reg;
  255. v4l_dbg(1, cx25840_debug, client, "decoder set video input %d, audio input %d\n",
  256. vid_input, aud_input);
  257. if (is_composite) {
  258. reg = 0xf0 + (vid_input - CX25840_COMPOSITE1);
  259. } else {
  260. int luma = vid_input & 0xf0;
  261. int chroma = vid_input & 0xf00;
  262. if ((vid_input & ~0xff0) ||
  263. luma < CX25840_SVIDEO_LUMA1 || luma > CX25840_SVIDEO_LUMA4 ||
  264. chroma < CX25840_SVIDEO_CHROMA4 || chroma > CX25840_SVIDEO_CHROMA8) {
  265. v4l_err(client, "0x%04x is not a valid video input!\n", vid_input);
  266. return -EINVAL;
  267. }
  268. reg = 0xf0 + ((luma - CX25840_SVIDEO_LUMA1) >> 4);
  269. if (chroma >= CX25840_SVIDEO_CHROMA7) {
  270. reg &= 0x3f;
  271. reg |= (chroma - CX25840_SVIDEO_CHROMA7) >> 2;
  272. } else {
  273. reg &= 0xcf;
  274. reg |= (chroma - CX25840_SVIDEO_CHROMA4) >> 4;
  275. }
  276. }
  277. switch (aud_input) {
  278. case CX25840_AUDIO_SERIAL:
  279. /* do nothing, use serial audio input */
  280. break;
  281. case CX25840_AUDIO4: reg &= ~0x30; break;
  282. case CX25840_AUDIO5: reg &= ~0x30; reg |= 0x10; break;
  283. case CX25840_AUDIO6: reg &= ~0x30; reg |= 0x20; break;
  284. case CX25840_AUDIO7: reg &= ~0xc0; break;
  285. case CX25840_AUDIO8: reg &= ~0xc0; reg |= 0x40; break;
  286. default:
  287. v4l_err(client, "0x%04x is not a valid audio input!\n", aud_input);
  288. return -EINVAL;
  289. }
  290. cx25840_write(client, 0x103, reg);
  291. /* Set INPUT_MODE to Composite (0) or S-Video (1) */
  292. cx25840_and_or(client, 0x401, ~0x6, is_composite ? 0 : 0x02);
  293. /* Set CH_SEL_ADC2 to 1 if input comes from CH3 */
  294. cx25840_and_or(client, 0x102, ~0x2, (reg & 0x80) == 0 ? 2 : 0);
  295. /* Set DUAL_MODE_ADC2 to 1 if input comes from both CH2 and CH3 */
  296. if ((reg & 0xc0) != 0xc0 && (reg & 0x30) != 0x30)
  297. cx25840_and_or(client, 0x102, ~0x4, 4);
  298. else
  299. cx25840_and_or(client, 0x102, ~0x4, 0);
  300. state->vid_input = vid_input;
  301. state->aud_input = aud_input;
  302. if (!state->is_cx25836) {
  303. cx25840_audio_set_path(client);
  304. input_change(client);
  305. }
  306. return 0;
  307. }
  308. /* ----------------------------------------------------------------------- */
  309. static int set_v4lstd(struct i2c_client *client, v4l2_std_id std)
  310. {
  311. u8 fmt=0; /* zero is autodetect */
  312. /* First tests should be against specific std */
  313. if (std == V4L2_STD_NTSC_M_JP) {
  314. fmt=0x2;
  315. } else if (std == V4L2_STD_NTSC_443) {
  316. fmt=0x3;
  317. } else if (std == V4L2_STD_PAL_M) {
  318. fmt=0x5;
  319. } else if (std == V4L2_STD_PAL_N) {
  320. fmt=0x6;
  321. } else if (std == V4L2_STD_PAL_Nc) {
  322. fmt=0x7;
  323. } else if (std == V4L2_STD_PAL_60) {
  324. fmt=0x8;
  325. } else {
  326. /* Then, test against generic ones */
  327. if (std & V4L2_STD_NTSC) {
  328. fmt=0x1;
  329. } else if (std & V4L2_STD_PAL) {
  330. fmt=0x4;
  331. } else if (std & V4L2_STD_SECAM) {
  332. fmt=0xc;
  333. }
  334. }
  335. v4l_dbg(1, cx25840_debug, client, "changing video std to fmt %i\n",fmt);
  336. /* Follow step 9 of section 3.16 in the cx25840 datasheet.
  337. Without this PAL may display a vertical ghosting effect.
  338. This happens for example with the Yuan MPC622. */
  339. if (fmt >= 4 && fmt < 8) {
  340. /* Set format to NTSC-M */
  341. cx25840_and_or(client, 0x400, ~0xf, 1);
  342. /* Turn off LCOMB */
  343. cx25840_and_or(client, 0x47b, ~6, 0);
  344. }
  345. cx25840_and_or(client, 0x400, ~0xf, fmt);
  346. cx25840_vbi_setup(client);
  347. return 0;
  348. }
  349. v4l2_std_id cx25840_get_v4lstd(struct i2c_client * client)
  350. {
  351. struct cx25840_state *state = i2c_get_clientdata(client);
  352. /* check VID_FMT_SEL first */
  353. u8 fmt = cx25840_read(client, 0x400) & 0xf;
  354. if (!fmt) {
  355. /* check AFD_FMT_STAT if set to autodetect */
  356. fmt = cx25840_read(client, 0x40d) & 0xf;
  357. }
  358. switch (fmt) {
  359. case 0x1:
  360. {
  361. /* if the audio std is A2-M, then this is the South Korean
  362. NTSC standard */
  363. if (!state->is_cx25836 && cx25840_read(client, 0x805) == 2)
  364. return V4L2_STD_NTSC_M_KR;
  365. return V4L2_STD_NTSC_M;
  366. }
  367. case 0x2: return V4L2_STD_NTSC_M_JP;
  368. case 0x3: return V4L2_STD_NTSC_443;
  369. case 0x4: return V4L2_STD_PAL;
  370. case 0x5: return V4L2_STD_PAL_M;
  371. case 0x6: return V4L2_STD_PAL_N;
  372. case 0x7: return V4L2_STD_PAL_Nc;
  373. case 0x8: return V4L2_STD_PAL_60;
  374. case 0xc: return V4L2_STD_SECAM;
  375. default: return V4L2_STD_UNKNOWN;
  376. }
  377. }
  378. /* ----------------------------------------------------------------------- */
  379. static int set_v4lctrl(struct i2c_client *client, struct v4l2_control *ctrl)
  380. {
  381. struct cx25840_state *state = i2c_get_clientdata(client);
  382. switch (ctrl->id) {
  383. case CX25840_CID_ENABLE_PVR150_WORKAROUND:
  384. state->pvr150_workaround = ctrl->value;
  385. set_input(client, state->vid_input, state->aud_input);
  386. break;
  387. case V4L2_CID_BRIGHTNESS:
  388. if (ctrl->value < 0 || ctrl->value > 255) {
  389. v4l_err(client, "invalid brightness setting %d\n",
  390. ctrl->value);
  391. return -ERANGE;
  392. }
  393. cx25840_write(client, 0x414, ctrl->value - 128);
  394. break;
  395. case V4L2_CID_CONTRAST:
  396. if (ctrl->value < 0 || ctrl->value > 127) {
  397. v4l_err(client, "invalid contrast setting %d\n",
  398. ctrl->value);
  399. return -ERANGE;
  400. }
  401. cx25840_write(client, 0x415, ctrl->value << 1);
  402. break;
  403. case V4L2_CID_SATURATION:
  404. if (ctrl->value < 0 || ctrl->value > 127) {
  405. v4l_err(client, "invalid saturation setting %d\n",
  406. ctrl->value);
  407. return -ERANGE;
  408. }
  409. cx25840_write(client, 0x420, ctrl->value << 1);
  410. cx25840_write(client, 0x421, ctrl->value << 1);
  411. break;
  412. case V4L2_CID_HUE:
  413. if (ctrl->value < -127 || ctrl->value > 127) {
  414. v4l_err(client, "invalid hue setting %d\n", ctrl->value);
  415. return -ERANGE;
  416. }
  417. cx25840_write(client, 0x422, ctrl->value);
  418. break;
  419. case V4L2_CID_AUDIO_VOLUME:
  420. case V4L2_CID_AUDIO_BASS:
  421. case V4L2_CID_AUDIO_TREBLE:
  422. case V4L2_CID_AUDIO_BALANCE:
  423. case V4L2_CID_AUDIO_MUTE:
  424. if (state->is_cx25836)
  425. return -EINVAL;
  426. return cx25840_audio(client, VIDIOC_S_CTRL, ctrl);
  427. default:
  428. return -EINVAL;
  429. }
  430. return 0;
  431. }
  432. static int get_v4lctrl(struct i2c_client *client, struct v4l2_control *ctrl)
  433. {
  434. struct cx25840_state *state = i2c_get_clientdata(client);
  435. switch (ctrl->id) {
  436. case CX25840_CID_ENABLE_PVR150_WORKAROUND:
  437. ctrl->value = state->pvr150_workaround;
  438. break;
  439. case V4L2_CID_BRIGHTNESS:
  440. ctrl->value = (s8)cx25840_read(client, 0x414) + 128;
  441. break;
  442. case V4L2_CID_CONTRAST:
  443. ctrl->value = cx25840_read(client, 0x415) >> 1;
  444. break;
  445. case V4L2_CID_SATURATION:
  446. ctrl->value = cx25840_read(client, 0x420) >> 1;
  447. break;
  448. case V4L2_CID_HUE:
  449. ctrl->value = (s8)cx25840_read(client, 0x422);
  450. break;
  451. case V4L2_CID_AUDIO_VOLUME:
  452. case V4L2_CID_AUDIO_BASS:
  453. case V4L2_CID_AUDIO_TREBLE:
  454. case V4L2_CID_AUDIO_BALANCE:
  455. case V4L2_CID_AUDIO_MUTE:
  456. if (state->is_cx25836)
  457. return -EINVAL;
  458. return cx25840_audio(client, VIDIOC_G_CTRL, ctrl);
  459. default:
  460. return -EINVAL;
  461. }
  462. return 0;
  463. }
  464. /* ----------------------------------------------------------------------- */
  465. static int get_v4lfmt(struct i2c_client *client, struct v4l2_format *fmt)
  466. {
  467. switch (fmt->type) {
  468. case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
  469. return cx25840_vbi(client, VIDIOC_G_FMT, fmt);
  470. default:
  471. return -EINVAL;
  472. }
  473. return 0;
  474. }
  475. static int set_v4lfmt(struct i2c_client *client, struct v4l2_format *fmt)
  476. {
  477. struct v4l2_pix_format *pix;
  478. int HSC, VSC, Vsrc, Hsrc, filter, Vlines;
  479. int is_50Hz = !(cx25840_get_v4lstd(client) & V4L2_STD_525_60);
  480. switch (fmt->type) {
  481. case V4L2_BUF_TYPE_VIDEO_CAPTURE:
  482. pix = &(fmt->fmt.pix);
  483. Vsrc = (cx25840_read(client, 0x476) & 0x3f) << 4;
  484. Vsrc |= (cx25840_read(client, 0x475) & 0xf0) >> 4;
  485. Hsrc = (cx25840_read(client, 0x472) & 0x3f) << 4;
  486. Hsrc |= (cx25840_read(client, 0x471) & 0xf0) >> 4;
  487. Vlines = pix->height + (is_50Hz ? 4 : 7);
  488. if ((pix->width * 16 < Hsrc) || (Hsrc < pix->width) ||
  489. (Vlines * 8 < Vsrc) || (Vsrc < Vlines)) {
  490. v4l_err(client, "%dx%d is not a valid size!\n",
  491. pix->width, pix->height);
  492. return -ERANGE;
  493. }
  494. HSC = (Hsrc * (1 << 20)) / pix->width - (1 << 20);
  495. VSC = (1 << 16) - (Vsrc * (1 << 9) / Vlines - (1 << 9));
  496. VSC &= 0x1fff;
  497. if (pix->width >= 385)
  498. filter = 0;
  499. else if (pix->width > 192)
  500. filter = 1;
  501. else if (pix->width > 96)
  502. filter = 2;
  503. else
  504. filter = 3;
  505. v4l_dbg(1, cx25840_debug, client, "decoder set size %dx%d -> scale %ux%u\n",
  506. pix->width, pix->height, HSC, VSC);
  507. /* HSCALE=HSC */
  508. cx25840_write(client, 0x418, HSC & 0xff);
  509. cx25840_write(client, 0x419, (HSC >> 8) & 0xff);
  510. cx25840_write(client, 0x41a, HSC >> 16);
  511. /* VSCALE=VSC */
  512. cx25840_write(client, 0x41c, VSC & 0xff);
  513. cx25840_write(client, 0x41d, VSC >> 8);
  514. /* VS_INTRLACE=1 VFILT=filter */
  515. cx25840_write(client, 0x41e, 0x8 | filter);
  516. break;
  517. case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
  518. return cx25840_vbi(client, VIDIOC_S_FMT, fmt);
  519. case V4L2_BUF_TYPE_VBI_CAPTURE:
  520. return cx25840_vbi(client, VIDIOC_S_FMT, fmt);
  521. default:
  522. return -EINVAL;
  523. }
  524. return 0;
  525. }
  526. /* ----------------------------------------------------------------------- */
  527. static int cx25840_command(struct i2c_client *client, unsigned int cmd,
  528. void *arg)
  529. {
  530. struct cx25840_state *state = i2c_get_clientdata(client);
  531. struct v4l2_tuner *vt = arg;
  532. struct v4l2_routing *route = arg;
  533. /* ignore these commands */
  534. switch (cmd) {
  535. case TUNER_SET_TYPE_ADDR:
  536. return 0;
  537. }
  538. if (!state->is_initialized) {
  539. v4l_dbg(1, cx25840_debug, client, "cmd %08x triggered fw load\n", cmd);
  540. /* initialize on first use */
  541. state->is_initialized = 1;
  542. if (state->is_cx25836)
  543. cx25836_initialize(client);
  544. else
  545. cx25840_initialize(client);
  546. }
  547. switch (cmd) {
  548. #ifdef CONFIG_VIDEO_ADV_DEBUG
  549. /* ioctls to allow direct access to the
  550. * cx25840 registers for testing */
  551. case VIDIOC_DBG_G_REGISTER:
  552. case VIDIOC_DBG_S_REGISTER:
  553. {
  554. struct v4l2_register *reg = arg;
  555. if (!v4l2_chip_match_i2c_client(client, reg->match_type, reg->match_chip))
  556. return -EINVAL;
  557. if (!capable(CAP_SYS_ADMIN))
  558. return -EPERM;
  559. if (cmd == VIDIOC_DBG_G_REGISTER)
  560. reg->val = cx25840_read(client, reg->reg & 0x0fff);
  561. else
  562. cx25840_write(client, reg->reg & 0x0fff, reg->val & 0xff);
  563. break;
  564. }
  565. #endif
  566. case VIDIOC_INT_DECODE_VBI_LINE:
  567. return cx25840_vbi(client, cmd, arg);
  568. case VIDIOC_INT_AUDIO_CLOCK_FREQ:
  569. return cx25840_audio(client, cmd, arg);
  570. case VIDIOC_STREAMON:
  571. v4l_dbg(1, cx25840_debug, client, "enable output\n");
  572. cx25840_write(client, 0x115, state->is_cx25836 ? 0x0c : 0x8c);
  573. cx25840_write(client, 0x116, state->is_cx25836 ? 0x04 : 0x07);
  574. break;
  575. case VIDIOC_STREAMOFF:
  576. v4l_dbg(1, cx25840_debug, client, "disable output\n");
  577. cx25840_write(client, 0x115, 0x00);
  578. cx25840_write(client, 0x116, 0x00);
  579. break;
  580. case VIDIOC_LOG_STATUS:
  581. log_video_status(client);
  582. if (!state->is_cx25836)
  583. log_audio_status(client);
  584. break;
  585. case VIDIOC_G_CTRL:
  586. return get_v4lctrl(client, (struct v4l2_control *)arg);
  587. case VIDIOC_S_CTRL:
  588. return set_v4lctrl(client, (struct v4l2_control *)arg);
  589. case VIDIOC_QUERYCTRL:
  590. {
  591. struct v4l2_queryctrl *qc = arg;
  592. switch (qc->id) {
  593. case V4L2_CID_BRIGHTNESS:
  594. case V4L2_CID_CONTRAST:
  595. case V4L2_CID_SATURATION:
  596. case V4L2_CID_HUE:
  597. return v4l2_ctrl_query_fill_std(qc);
  598. default:
  599. break;
  600. }
  601. if (state->is_cx25836)
  602. return -EINVAL;
  603. switch (qc->id) {
  604. case V4L2_CID_AUDIO_VOLUME:
  605. case V4L2_CID_AUDIO_MUTE:
  606. case V4L2_CID_AUDIO_BALANCE:
  607. case V4L2_CID_AUDIO_BASS:
  608. case V4L2_CID_AUDIO_TREBLE:
  609. return v4l2_ctrl_query_fill_std(qc);
  610. default:
  611. return -EINVAL;
  612. }
  613. return -EINVAL;
  614. }
  615. case VIDIOC_G_STD:
  616. *(v4l2_std_id *)arg = cx25840_get_v4lstd(client);
  617. break;
  618. case VIDIOC_S_STD:
  619. state->radio = 0;
  620. return set_v4lstd(client, *(v4l2_std_id *)arg);
  621. case AUDC_SET_RADIO:
  622. state->radio = 1;
  623. break;
  624. case VIDIOC_INT_G_VIDEO_ROUTING:
  625. route->input = state->vid_input;
  626. route->output = 0;
  627. break;
  628. case VIDIOC_INT_S_VIDEO_ROUTING:
  629. return set_input(client, route->input, state->aud_input);
  630. case VIDIOC_INT_G_AUDIO_ROUTING:
  631. if (state->is_cx25836)
  632. return -EINVAL;
  633. route->input = state->aud_input;
  634. route->output = 0;
  635. break;
  636. case VIDIOC_INT_S_AUDIO_ROUTING:
  637. if (state->is_cx25836)
  638. return -EINVAL;
  639. return set_input(client, state->vid_input, route->input);
  640. case VIDIOC_S_FREQUENCY:
  641. if (!state->is_cx25836) {
  642. input_change(client);
  643. }
  644. break;
  645. case VIDIOC_G_TUNER:
  646. {
  647. u8 vpres = cx25840_read(client, 0x40e) & 0x20;
  648. u8 mode;
  649. int val = 0;
  650. if (state->radio)
  651. break;
  652. vt->signal = vpres ? 0xffff : 0x0;
  653. if (state->is_cx25836)
  654. break;
  655. vt->capability |=
  656. V4L2_TUNER_CAP_STEREO | V4L2_TUNER_CAP_LANG1 |
  657. V4L2_TUNER_CAP_LANG2 | V4L2_TUNER_CAP_SAP;
  658. mode = cx25840_read(client, 0x804);
  659. /* get rxsubchans and audmode */
  660. if ((mode & 0xf) == 1)
  661. val |= V4L2_TUNER_SUB_STEREO;
  662. else
  663. val |= V4L2_TUNER_SUB_MONO;
  664. if (mode == 2 || mode == 4)
  665. val = V4L2_TUNER_SUB_LANG1 | V4L2_TUNER_SUB_LANG2;
  666. if (mode & 0x10)
  667. val |= V4L2_TUNER_SUB_SAP;
  668. vt->rxsubchans = val;
  669. vt->audmode = state->audmode;
  670. break;
  671. }
  672. case VIDIOC_S_TUNER:
  673. if (state->radio || state->is_cx25836)
  674. break;
  675. switch (vt->audmode) {
  676. case V4L2_TUNER_MODE_MONO:
  677. /* mono -> mono
  678. stereo -> mono
  679. bilingual -> lang1 */
  680. cx25840_and_or(client, 0x809, ~0xf, 0x00);
  681. break;
  682. case V4L2_TUNER_MODE_STEREO:
  683. case V4L2_TUNER_MODE_LANG1:
  684. /* mono -> mono
  685. stereo -> stereo
  686. bilingual -> lang1 */
  687. cx25840_and_or(client, 0x809, ~0xf, 0x04);
  688. break;
  689. case V4L2_TUNER_MODE_LANG1_LANG2:
  690. /* mono -> mono
  691. stereo -> stereo
  692. bilingual -> lang1/lang2 */
  693. cx25840_and_or(client, 0x809, ~0xf, 0x07);
  694. break;
  695. case V4L2_TUNER_MODE_LANG2:
  696. /* mono -> mono
  697. stereo -> stereo
  698. bilingual -> lang2 */
  699. cx25840_and_or(client, 0x809, ~0xf, 0x01);
  700. break;
  701. default:
  702. return -EINVAL;
  703. }
  704. state->audmode = vt->audmode;
  705. break;
  706. case VIDIOC_G_FMT:
  707. return get_v4lfmt(client, (struct v4l2_format *)arg);
  708. case VIDIOC_S_FMT:
  709. return set_v4lfmt(client, (struct v4l2_format *)arg);
  710. case VIDIOC_INT_RESET:
  711. if (state->is_cx25836)
  712. cx25836_initialize(client);
  713. else
  714. cx25840_initialize(client);
  715. break;
  716. case VIDIOC_G_CHIP_IDENT:
  717. return v4l2_chip_ident_i2c_client(client, arg, state->id, state->rev);
  718. default:
  719. return -EINVAL;
  720. }
  721. return 0;
  722. }
  723. /* ----------------------------------------------------------------------- */
  724. static struct i2c_driver i2c_driver_cx25840;
  725. static int cx25840_detect_client(struct i2c_adapter *adapter, int address,
  726. int kind)
  727. {
  728. struct i2c_client *client;
  729. struct cx25840_state *state;
  730. u32 id;
  731. u16 device_id;
  732. /* Check if the adapter supports the needed features
  733. * Not until kernel version 2.6.11 did the bit-algo
  734. * correctly report that it would do an I2C-level xfer */
  735. if (!i2c_check_functionality(adapter, I2C_FUNC_I2C))
  736. return 0;
  737. state = kzalloc(sizeof(struct cx25840_state), GFP_KERNEL);
  738. if (state == 0)
  739. return -ENOMEM;
  740. client = &state->c;
  741. client->addr = address;
  742. client->adapter = adapter;
  743. client->driver = &i2c_driver_cx25840;
  744. snprintf(client->name, sizeof(client->name) - 1, "cx25840");
  745. v4l_dbg(1, cx25840_debug, client, "detecting cx25840 client on address 0x%x\n", address << 1);
  746. device_id = cx25840_read(client, 0x101) << 8;
  747. device_id |= cx25840_read(client, 0x100);
  748. /* The high byte of the device ID should be
  749. * 0x83 for the cx2583x and 0x84 for the cx2584x */
  750. if ((device_id & 0xff00) == 0x8300) {
  751. id = V4L2_IDENT_CX25836 + ((device_id >> 4) & 0xf) - 6;
  752. state->is_cx25836 = 1;
  753. }
  754. else if ((device_id & 0xff00) == 0x8400) {
  755. id = V4L2_IDENT_CX25840 + ((device_id >> 4) & 0xf);
  756. state->is_cx25836 = 0;
  757. }
  758. else {
  759. v4l_dbg(1, cx25840_debug, client, "cx25840 not found\n");
  760. kfree(state);
  761. return 0;
  762. }
  763. /* Note: revision '(device_id & 0x0f) == 2' was never built. The
  764. marking skips from 0x1 == 22 to 0x3 == 23. */
  765. v4l_info(client, "cx25%3x-2%x found @ 0x%x (%s)\n",
  766. (device_id & 0xfff0) >> 4,
  767. (device_id & 0x0f) < 3 ? (device_id & 0x0f) + 1 : (device_id & 0x0f),
  768. address << 1, adapter->name);
  769. i2c_set_clientdata(client, state);
  770. state->vid_input = CX25840_COMPOSITE7;
  771. state->aud_input = CX25840_AUDIO8;
  772. state->audclk_freq = 48000;
  773. state->pvr150_workaround = 0;
  774. state->audmode = V4L2_TUNER_MODE_LANG1;
  775. state->unmute_volume = -1;
  776. state->vbi_line_offset = 8;
  777. state->id = id;
  778. state->rev = device_id;
  779. i2c_attach_client(client);
  780. return 0;
  781. }
  782. static int cx25840_attach_adapter(struct i2c_adapter *adapter)
  783. {
  784. if (adapter->class & I2C_CLASS_TV_ANALOG)
  785. return i2c_probe(adapter, &addr_data, &cx25840_detect_client);
  786. return 0;
  787. }
  788. static int cx25840_detach_client(struct i2c_client *client)
  789. {
  790. struct cx25840_state *state = i2c_get_clientdata(client);
  791. int err;
  792. err = i2c_detach_client(client);
  793. if (err) {
  794. return err;
  795. }
  796. kfree(state);
  797. return 0;
  798. }
  799. /* ----------------------------------------------------------------------- */
  800. static struct i2c_driver i2c_driver_cx25840 = {
  801. .driver = {
  802. .name = "cx25840",
  803. },
  804. .id = I2C_DRIVERID_CX25840,
  805. .attach_adapter = cx25840_attach_adapter,
  806. .detach_client = cx25840_detach_client,
  807. .command = cx25840_command,
  808. };
  809. static int __init m__init(void)
  810. {
  811. return i2c_add_driver(&i2c_driver_cx25840);
  812. }
  813. static void __exit m__exit(void)
  814. {
  815. i2c_del_driver(&i2c_driver_cx25840);
  816. }
  817. module_init(m__init);
  818. module_exit(m__exit);
  819. /* ----------------------------------------------------------------------- */
  820. static void log_video_status(struct i2c_client *client)
  821. {
  822. static const char *const fmt_strs[] = {
  823. "0x0",
  824. "NTSC-M", "NTSC-J", "NTSC-4.43",
  825. "PAL-BDGHI", "PAL-M", "PAL-N", "PAL-Nc", "PAL-60",
  826. "0x9", "0xA", "0xB",
  827. "SECAM",
  828. "0xD", "0xE", "0xF"
  829. };
  830. struct cx25840_state *state = i2c_get_clientdata(client);
  831. u8 vidfmt_sel = cx25840_read(client, 0x400) & 0xf;
  832. u8 gen_stat1 = cx25840_read(client, 0x40d);
  833. u8 gen_stat2 = cx25840_read(client, 0x40e);
  834. int vid_input = state->vid_input;
  835. v4l_info(client, "Video signal: %spresent\n",
  836. (gen_stat2 & 0x20) ? "" : "not ");
  837. v4l_info(client, "Detected format: %s\n",
  838. fmt_strs[gen_stat1 & 0xf]);
  839. v4l_info(client, "Specified standard: %s\n",
  840. vidfmt_sel ? fmt_strs[vidfmt_sel] : "automatic detection");
  841. if (vid_input >= CX25840_COMPOSITE1 &&
  842. vid_input <= CX25840_COMPOSITE8) {
  843. v4l_info(client, "Specified video input: Composite %d\n",
  844. vid_input - CX25840_COMPOSITE1 + 1);
  845. } else {
  846. v4l_info(client, "Specified video input: S-Video (Luma In%d, Chroma In%d)\n",
  847. (vid_input & 0xf0) >> 4, (vid_input & 0xf00) >> 8);
  848. }
  849. v4l_info(client, "Specified audioclock freq: %d Hz\n", state->audclk_freq);
  850. }
  851. /* ----------------------------------------------------------------------- */
  852. static void log_audio_status(struct i2c_client *client)
  853. {
  854. struct cx25840_state *state = i2c_get_clientdata(client);
  855. u8 download_ctl = cx25840_read(client, 0x803);
  856. u8 mod_det_stat0 = cx25840_read(client, 0x804);
  857. u8 mod_det_stat1 = cx25840_read(client, 0x805);
  858. u8 audio_config = cx25840_read(client, 0x808);
  859. u8 pref_mode = cx25840_read(client, 0x809);
  860. u8 afc0 = cx25840_read(client, 0x80b);
  861. u8 mute_ctl = cx25840_read(client, 0x8d3);
  862. int aud_input = state->aud_input;
  863. char *p;
  864. switch (mod_det_stat0) {
  865. case 0x00: p = "mono"; break;
  866. case 0x01: p = "stereo"; break;
  867. case 0x02: p = "dual"; break;
  868. case 0x04: p = "tri"; break;
  869. case 0x10: p = "mono with SAP"; break;
  870. case 0x11: p = "stereo with SAP"; break;
  871. case 0x12: p = "dual with SAP"; break;
  872. case 0x14: p = "tri with SAP"; break;
  873. case 0xfe: p = "forced mode"; break;
  874. default: p = "not defined";
  875. }
  876. v4l_info(client, "Detected audio mode: %s\n", p);
  877. switch (mod_det_stat1) {
  878. case 0x00: p = "not defined"; break;
  879. case 0x01: p = "EIAJ"; break;
  880. case 0x02: p = "A2-M"; break;
  881. case 0x03: p = "A2-BG"; break;
  882. case 0x04: p = "A2-DK1"; break;
  883. case 0x05: p = "A2-DK2"; break;
  884. case 0x06: p = "A2-DK3"; break;
  885. case 0x07: p = "A1 (6.0 MHz FM Mono)"; break;
  886. case 0x08: p = "AM-L"; break;
  887. case 0x09: p = "NICAM-BG"; break;
  888. case 0x0a: p = "NICAM-DK"; break;
  889. case 0x0b: p = "NICAM-I"; break;
  890. case 0x0c: p = "NICAM-L"; break;
  891. case 0x0d: p = "BTSC/EIAJ/A2-M Mono (4.5 MHz FMMono)"; break;
  892. case 0x0e: p = "IF FM Radio"; break;
  893. case 0x0f: p = "BTSC"; break;
  894. case 0x10: p = "high-deviation FM"; break;
  895. case 0x11: p = "very high-deviation FM"; break;
  896. case 0xfd: p = "unknown audio standard"; break;
  897. case 0xfe: p = "forced audio standard"; break;
  898. case 0xff: p = "no detected audio standard"; break;
  899. default: p = "not defined";
  900. }
  901. v4l_info(client, "Detected audio standard: %s\n", p);
  902. v4l_info(client, "Audio muted: %s\n",
  903. (state->unmute_volume >= 0) ? "yes" : "no");
  904. v4l_info(client, "Audio microcontroller: %s\n",
  905. (download_ctl & 0x10) ?
  906. ((mute_ctl & 0x2) ? "detecting" : "running") : "stopped");
  907. switch (audio_config >> 4) {
  908. case 0x00: p = "undefined"; break;
  909. case 0x01: p = "BTSC"; break;
  910. case 0x02: p = "EIAJ"; break;
  911. case 0x03: p = "A2-M"; break;
  912. case 0x04: p = "A2-BG"; break;
  913. case 0x05: p = "A2-DK1"; break;
  914. case 0x06: p = "A2-DK2"; break;
  915. case 0x07: p = "A2-DK3"; break;
  916. case 0x08: p = "A1 (6.0 MHz FM Mono)"; break;
  917. case 0x09: p = "AM-L"; break;
  918. case 0x0a: p = "NICAM-BG"; break;
  919. case 0x0b: p = "NICAM-DK"; break;
  920. case 0x0c: p = "NICAM-I"; break;
  921. case 0x0d: p = "NICAM-L"; break;
  922. case 0x0e: p = "FM radio"; break;
  923. case 0x0f: p = "automatic detection"; break;
  924. default: p = "undefined";
  925. }
  926. v4l_info(client, "Configured audio standard: %s\n", p);
  927. if ((audio_config >> 4) < 0xF) {
  928. switch (audio_config & 0xF) {
  929. case 0x00: p = "MONO1 (LANGUAGE A/Mono L+R channel for BTSC, EIAJ, A2)"; break;
  930. case 0x01: p = "MONO2 (LANGUAGE B)"; break;
  931. case 0x02: p = "MONO3 (STEREO forced MONO)"; break;
  932. case 0x03: p = "MONO4 (NICAM ANALOG-Language C/Analog Fallback)"; break;
  933. case 0x04: p = "STEREO"; break;
  934. case 0x05: p = "DUAL1 (AB)"; break;
  935. case 0x06: p = "DUAL2 (AC) (FM)"; break;
  936. case 0x07: p = "DUAL3 (BC) (FM)"; break;
  937. case 0x08: p = "DUAL4 (AC) (AM)"; break;
  938. case 0x09: p = "DUAL5 (BC) (AM)"; break;
  939. case 0x0a: p = "SAP"; break;
  940. default: p = "undefined";
  941. }
  942. v4l_info(client, "Configured audio mode: %s\n", p);
  943. } else {
  944. switch (audio_config & 0xF) {
  945. case 0x00: p = "BG"; break;
  946. case 0x01: p = "DK1"; break;
  947. case 0x02: p = "DK2"; break;
  948. case 0x03: p = "DK3"; break;
  949. case 0x04: p = "I"; break;
  950. case 0x05: p = "L"; break;
  951. case 0x06: p = "BTSC"; break;
  952. case 0x07: p = "EIAJ"; break;
  953. case 0x08: p = "A2-M"; break;
  954. case 0x09: p = "FM Radio"; break;
  955. case 0x0f: p = "automatic standard and mode detection"; break;
  956. default: p = "undefined";
  957. }
  958. v4l_info(client, "Configured audio system: %s\n", p);
  959. }
  960. if (aud_input) {
  961. v4l_info(client, "Specified audio input: Tuner (In%d)\n", aud_input);
  962. } else {
  963. v4l_info(client, "Specified audio input: External\n");
  964. }
  965. switch (pref_mode & 0xf) {
  966. case 0: p = "mono/language A"; break;
  967. case 1: p = "language B"; break;
  968. case 2: p = "language C"; break;
  969. case 3: p = "analog fallback"; break;
  970. case 4: p = "stereo"; break;
  971. case 5: p = "language AC"; break;
  972. case 6: p = "language BC"; break;
  973. case 7: p = "language AB"; break;
  974. default: p = "undefined";
  975. }
  976. v4l_info(client, "Preferred audio mode: %s\n", p);
  977. if ((audio_config & 0xf) == 0xf) {
  978. switch ((afc0 >> 3) & 0x3) {
  979. case 0: p = "system DK"; break;
  980. case 1: p = "system L"; break;
  981. case 2: p = "autodetect"; break;
  982. default: p = "undefined";
  983. }
  984. v4l_info(client, "Selected 65 MHz format: %s\n", p);
  985. switch (afc0 & 0x7) {
  986. case 0: p = "chroma"; break;
  987. case 1: p = "BTSC"; break;
  988. case 2: p = "EIAJ"; break;
  989. case 3: p = "A2-M"; break;
  990. case 4: p = "autodetect"; break;
  991. default: p = "undefined";
  992. }
  993. v4l_info(client, "Selected 45 MHz format: %s\n", p);
  994. }
  995. }