cx25840-core.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169
  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. cx25840_and_or(client, 0x810, ~0x01, 1);
  216. if (state->radio) {
  217. cx25840_write(client, 0x808, 0xf9);
  218. cx25840_write(client, 0x80b, 0x00);
  219. }
  220. else if (std & V4L2_STD_525_60) {
  221. /* Certain Hauppauge PVR150 models have a hardware bug
  222. that causes audio to drop out. For these models the
  223. audio standard must be set explicitly.
  224. To be precise: it affects cards with tuner models
  225. 85, 99 and 112 (model numbers from tveeprom). */
  226. int hw_fix = state->pvr150_workaround;
  227. if (std == V4L2_STD_NTSC_M_JP) {
  228. /* Japan uses EIAJ audio standard */
  229. cx25840_write(client, 0x808, hw_fix ? 0x2f : 0xf7);
  230. } else if (std == V4L2_STD_NTSC_M_KR) {
  231. /* South Korea uses A2 audio standard */
  232. cx25840_write(client, 0x808, hw_fix ? 0x3f : 0xf8);
  233. } else {
  234. /* Others use the BTSC audio standard */
  235. cx25840_write(client, 0x808, hw_fix ? 0x1f : 0xf6);
  236. }
  237. cx25840_write(client, 0x80b, 0x00);
  238. } else if (std & V4L2_STD_PAL) {
  239. /* Follow tuner change procedure for PAL */
  240. cx25840_write(client, 0x808, 0xff);
  241. cx25840_write(client, 0x80b, 0x10);
  242. } else if (std & V4L2_STD_SECAM) {
  243. /* Select autodetect for SECAM */
  244. cx25840_write(client, 0x808, 0xff);
  245. cx25840_write(client, 0x80b, 0x10);
  246. }
  247. cx25840_and_or(client, 0x810, ~0x01, 0);
  248. }
  249. static int set_input(struct i2c_client *client, enum cx25840_video_input vid_input,
  250. enum cx25840_audio_input aud_input)
  251. {
  252. struct cx25840_state *state = i2c_get_clientdata(client);
  253. u8 is_composite = (vid_input >= CX25840_COMPOSITE1 &&
  254. vid_input <= CX25840_COMPOSITE8);
  255. u8 reg;
  256. v4l_dbg(1, cx25840_debug, client, "decoder set video input %d, audio input %d\n",
  257. vid_input, aud_input);
  258. if (is_composite) {
  259. reg = 0xf0 + (vid_input - CX25840_COMPOSITE1);
  260. } else {
  261. int luma = vid_input & 0xf0;
  262. int chroma = vid_input & 0xf00;
  263. if ((vid_input & ~0xff0) ||
  264. luma < CX25840_SVIDEO_LUMA1 || luma > CX25840_SVIDEO_LUMA4 ||
  265. chroma < CX25840_SVIDEO_CHROMA4 || chroma > CX25840_SVIDEO_CHROMA8) {
  266. v4l_err(client, "0x%04x is not a valid video input!\n", vid_input);
  267. return -EINVAL;
  268. }
  269. reg = 0xf0 + ((luma - CX25840_SVIDEO_LUMA1) >> 4);
  270. if (chroma >= CX25840_SVIDEO_CHROMA7) {
  271. reg &= 0x3f;
  272. reg |= (chroma - CX25840_SVIDEO_CHROMA7) >> 2;
  273. } else {
  274. reg &= 0xcf;
  275. reg |= (chroma - CX25840_SVIDEO_CHROMA4) >> 4;
  276. }
  277. }
  278. switch (aud_input) {
  279. case CX25840_AUDIO_SERIAL:
  280. /* do nothing, use serial audio input */
  281. break;
  282. case CX25840_AUDIO4: reg &= ~0x30; break;
  283. case CX25840_AUDIO5: reg &= ~0x30; reg |= 0x10; break;
  284. case CX25840_AUDIO6: reg &= ~0x30; reg |= 0x20; break;
  285. case CX25840_AUDIO7: reg &= ~0xc0; break;
  286. case CX25840_AUDIO8: reg &= ~0xc0; reg |= 0x40; break;
  287. default:
  288. v4l_err(client, "0x%04x is not a valid audio input!\n", aud_input);
  289. return -EINVAL;
  290. }
  291. cx25840_write(client, 0x103, reg);
  292. /* Set INPUT_MODE to Composite (0) or S-Video (1) */
  293. cx25840_and_or(client, 0x401, ~0x6, is_composite ? 0 : 0x02);
  294. /* Set CH_SEL_ADC2 to 1 if input comes from CH3 */
  295. cx25840_and_or(client, 0x102, ~0x2, (reg & 0x80) == 0 ? 2 : 0);
  296. /* Set DUAL_MODE_ADC2 to 1 if input comes from both CH2 and CH3 */
  297. if ((reg & 0xc0) != 0xc0 && (reg & 0x30) != 0x30)
  298. cx25840_and_or(client, 0x102, ~0x4, 4);
  299. else
  300. cx25840_and_or(client, 0x102, ~0x4, 0);
  301. state->vid_input = vid_input;
  302. state->aud_input = aud_input;
  303. if (!state->is_cx25836) {
  304. cx25840_audio_set_path(client);
  305. input_change(client);
  306. }
  307. return 0;
  308. }
  309. /* ----------------------------------------------------------------------- */
  310. static int set_v4lstd(struct i2c_client *client, v4l2_std_id std)
  311. {
  312. u8 fmt=0; /* zero is autodetect */
  313. /* First tests should be against specific std */
  314. if (std == V4L2_STD_NTSC_M_JP) {
  315. fmt=0x2;
  316. } else if (std == V4L2_STD_NTSC_443) {
  317. fmt=0x3;
  318. } else if (std == V4L2_STD_PAL_M) {
  319. fmt=0x5;
  320. } else if (std == V4L2_STD_PAL_N) {
  321. fmt=0x6;
  322. } else if (std == V4L2_STD_PAL_Nc) {
  323. fmt=0x7;
  324. } else if (std == V4L2_STD_PAL_60) {
  325. fmt=0x8;
  326. } else {
  327. /* Then, test against generic ones */
  328. if (std & V4L2_STD_NTSC) {
  329. fmt=0x1;
  330. } else if (std & V4L2_STD_PAL) {
  331. fmt=0x4;
  332. } else if (std & V4L2_STD_SECAM) {
  333. fmt=0xc;
  334. }
  335. }
  336. v4l_dbg(1, cx25840_debug, client, "changing video std to fmt %i\n",fmt);
  337. /* Follow step 9 of section 3.16 in the cx25840 datasheet.
  338. Without this PAL may display a vertical ghosting effect.
  339. This happens for example with the Yuan MPC622. */
  340. if (fmt >= 4 && fmt < 8) {
  341. /* Set format to NTSC-M */
  342. cx25840_and_or(client, 0x400, ~0xf, 1);
  343. /* Turn off LCOMB */
  344. cx25840_and_or(client, 0x47b, ~6, 0);
  345. }
  346. cx25840_and_or(client, 0x400, ~0xf, fmt);
  347. cx25840_vbi_setup(client);
  348. return 0;
  349. }
  350. v4l2_std_id cx25840_get_v4lstd(struct i2c_client * client)
  351. {
  352. struct cx25840_state *state = i2c_get_clientdata(client);
  353. /* check VID_FMT_SEL first */
  354. u8 fmt = cx25840_read(client, 0x400) & 0xf;
  355. if (!fmt) {
  356. /* check AFD_FMT_STAT if set to autodetect */
  357. fmt = cx25840_read(client, 0x40d) & 0xf;
  358. }
  359. switch (fmt) {
  360. case 0x1:
  361. {
  362. /* if the audio std is A2-M, then this is the South Korean
  363. NTSC standard */
  364. if (!state->is_cx25836 && cx25840_read(client, 0x805) == 2)
  365. return V4L2_STD_NTSC_M_KR;
  366. return V4L2_STD_NTSC_M;
  367. }
  368. case 0x2: return V4L2_STD_NTSC_M_JP;
  369. case 0x3: return V4L2_STD_NTSC_443;
  370. case 0x4: return V4L2_STD_PAL;
  371. case 0x5: return V4L2_STD_PAL_M;
  372. case 0x6: return V4L2_STD_PAL_N;
  373. case 0x7: return V4L2_STD_PAL_Nc;
  374. case 0x8: return V4L2_STD_PAL_60;
  375. case 0xc: return V4L2_STD_SECAM;
  376. default: return V4L2_STD_UNKNOWN;
  377. }
  378. }
  379. /* ----------------------------------------------------------------------- */
  380. static int set_v4lctrl(struct i2c_client *client, struct v4l2_control *ctrl)
  381. {
  382. struct cx25840_state *state = i2c_get_clientdata(client);
  383. switch (ctrl->id) {
  384. case CX25840_CID_ENABLE_PVR150_WORKAROUND:
  385. state->pvr150_workaround = ctrl->value;
  386. set_input(client, state->vid_input, state->aud_input);
  387. break;
  388. case V4L2_CID_BRIGHTNESS:
  389. if (ctrl->value < 0 || ctrl->value > 255) {
  390. v4l_err(client, "invalid brightness setting %d\n",
  391. ctrl->value);
  392. return -ERANGE;
  393. }
  394. cx25840_write(client, 0x414, ctrl->value - 128);
  395. break;
  396. case V4L2_CID_CONTRAST:
  397. if (ctrl->value < 0 || ctrl->value > 127) {
  398. v4l_err(client, "invalid contrast setting %d\n",
  399. ctrl->value);
  400. return -ERANGE;
  401. }
  402. cx25840_write(client, 0x415, ctrl->value << 1);
  403. break;
  404. case V4L2_CID_SATURATION:
  405. if (ctrl->value < 0 || ctrl->value > 127) {
  406. v4l_err(client, "invalid saturation setting %d\n",
  407. ctrl->value);
  408. return -ERANGE;
  409. }
  410. cx25840_write(client, 0x420, ctrl->value << 1);
  411. cx25840_write(client, 0x421, ctrl->value << 1);
  412. break;
  413. case V4L2_CID_HUE:
  414. if (ctrl->value < -127 || ctrl->value > 127) {
  415. v4l_err(client, "invalid hue setting %d\n", ctrl->value);
  416. return -ERANGE;
  417. }
  418. cx25840_write(client, 0x422, ctrl->value);
  419. break;
  420. case V4L2_CID_AUDIO_VOLUME:
  421. case V4L2_CID_AUDIO_BASS:
  422. case V4L2_CID_AUDIO_TREBLE:
  423. case V4L2_CID_AUDIO_BALANCE:
  424. case V4L2_CID_AUDIO_MUTE:
  425. if (state->is_cx25836)
  426. return -EINVAL;
  427. return cx25840_audio(client, VIDIOC_S_CTRL, ctrl);
  428. default:
  429. return -EINVAL;
  430. }
  431. return 0;
  432. }
  433. static int get_v4lctrl(struct i2c_client *client, struct v4l2_control *ctrl)
  434. {
  435. struct cx25840_state *state = i2c_get_clientdata(client);
  436. switch (ctrl->id) {
  437. case CX25840_CID_ENABLE_PVR150_WORKAROUND:
  438. ctrl->value = state->pvr150_workaround;
  439. break;
  440. case V4L2_CID_BRIGHTNESS:
  441. ctrl->value = (s8)cx25840_read(client, 0x414) + 128;
  442. break;
  443. case V4L2_CID_CONTRAST:
  444. ctrl->value = cx25840_read(client, 0x415) >> 1;
  445. break;
  446. case V4L2_CID_SATURATION:
  447. ctrl->value = cx25840_read(client, 0x420) >> 1;
  448. break;
  449. case V4L2_CID_HUE:
  450. ctrl->value = (s8)cx25840_read(client, 0x422);
  451. break;
  452. case V4L2_CID_AUDIO_VOLUME:
  453. case V4L2_CID_AUDIO_BASS:
  454. case V4L2_CID_AUDIO_TREBLE:
  455. case V4L2_CID_AUDIO_BALANCE:
  456. case V4L2_CID_AUDIO_MUTE:
  457. if (state->is_cx25836)
  458. return -EINVAL;
  459. return cx25840_audio(client, VIDIOC_G_CTRL, ctrl);
  460. default:
  461. return -EINVAL;
  462. }
  463. return 0;
  464. }
  465. /* ----------------------------------------------------------------------- */
  466. static int get_v4lfmt(struct i2c_client *client, struct v4l2_format *fmt)
  467. {
  468. switch (fmt->type) {
  469. case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
  470. return cx25840_vbi(client, VIDIOC_G_FMT, fmt);
  471. default:
  472. return -EINVAL;
  473. }
  474. return 0;
  475. }
  476. static int set_v4lfmt(struct i2c_client *client, struct v4l2_format *fmt)
  477. {
  478. struct v4l2_pix_format *pix;
  479. int HSC, VSC, Vsrc, Hsrc, filter, Vlines;
  480. int is_50Hz = !(cx25840_get_v4lstd(client) & V4L2_STD_525_60);
  481. switch (fmt->type) {
  482. case V4L2_BUF_TYPE_VIDEO_CAPTURE:
  483. pix = &(fmt->fmt.pix);
  484. Vsrc = (cx25840_read(client, 0x476) & 0x3f) << 4;
  485. Vsrc |= (cx25840_read(client, 0x475) & 0xf0) >> 4;
  486. Hsrc = (cx25840_read(client, 0x472) & 0x3f) << 4;
  487. Hsrc |= (cx25840_read(client, 0x471) & 0xf0) >> 4;
  488. Vlines = pix->height + (is_50Hz ? 4 : 7);
  489. if ((pix->width * 16 < Hsrc) || (Hsrc < pix->width) ||
  490. (Vlines * 8 < Vsrc) || (Vsrc < Vlines)) {
  491. v4l_err(client, "%dx%d is not a valid size!\n",
  492. pix->width, pix->height);
  493. return -ERANGE;
  494. }
  495. HSC = (Hsrc * (1 << 20)) / pix->width - (1 << 20);
  496. VSC = (1 << 16) - (Vsrc * (1 << 9) / Vlines - (1 << 9));
  497. VSC &= 0x1fff;
  498. if (pix->width >= 385)
  499. filter = 0;
  500. else if (pix->width > 192)
  501. filter = 1;
  502. else if (pix->width > 96)
  503. filter = 2;
  504. else
  505. filter = 3;
  506. v4l_dbg(1, cx25840_debug, client, "decoder set size %dx%d -> scale %ux%u\n",
  507. pix->width, pix->height, HSC, VSC);
  508. /* HSCALE=HSC */
  509. cx25840_write(client, 0x418, HSC & 0xff);
  510. cx25840_write(client, 0x419, (HSC >> 8) & 0xff);
  511. cx25840_write(client, 0x41a, HSC >> 16);
  512. /* VSCALE=VSC */
  513. cx25840_write(client, 0x41c, VSC & 0xff);
  514. cx25840_write(client, 0x41d, VSC >> 8);
  515. /* VS_INTRLACE=1 VFILT=filter */
  516. cx25840_write(client, 0x41e, 0x8 | filter);
  517. break;
  518. case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
  519. return cx25840_vbi(client, VIDIOC_S_FMT, fmt);
  520. case V4L2_BUF_TYPE_VBI_CAPTURE:
  521. return cx25840_vbi(client, VIDIOC_S_FMT, fmt);
  522. default:
  523. return -EINVAL;
  524. }
  525. return 0;
  526. }
  527. /* ----------------------------------------------------------------------- */
  528. static int cx25840_command(struct i2c_client *client, unsigned int cmd,
  529. void *arg)
  530. {
  531. struct cx25840_state *state = i2c_get_clientdata(client);
  532. struct v4l2_tuner *vt = arg;
  533. struct v4l2_routing *route = arg;
  534. /* ignore these commands */
  535. switch (cmd) {
  536. case TUNER_SET_TYPE_ADDR:
  537. return 0;
  538. }
  539. if (!state->is_initialized) {
  540. v4l_dbg(1, cx25840_debug, client, "cmd %08x triggered fw load\n", cmd);
  541. /* initialize on first use */
  542. state->is_initialized = 1;
  543. if (state->is_cx25836)
  544. cx25836_initialize(client);
  545. else
  546. cx25840_initialize(client);
  547. }
  548. switch (cmd) {
  549. #ifdef CONFIG_VIDEO_ADV_DEBUG
  550. /* ioctls to allow direct access to the
  551. * cx25840 registers for testing */
  552. case VIDIOC_DBG_G_REGISTER:
  553. case VIDIOC_DBG_S_REGISTER:
  554. {
  555. struct v4l2_register *reg = arg;
  556. if (!v4l2_chip_match_i2c_client(client, reg->match_type, reg->match_chip))
  557. return -EINVAL;
  558. if (!capable(CAP_SYS_ADMIN))
  559. return -EPERM;
  560. if (cmd == VIDIOC_DBG_G_REGISTER)
  561. reg->val = cx25840_read(client, reg->reg & 0x0fff);
  562. else
  563. cx25840_write(client, reg->reg & 0x0fff, reg->val & 0xff);
  564. break;
  565. }
  566. #endif
  567. case VIDIOC_INT_DECODE_VBI_LINE:
  568. return cx25840_vbi(client, cmd, arg);
  569. case VIDIOC_INT_AUDIO_CLOCK_FREQ:
  570. return cx25840_audio(client, cmd, arg);
  571. case VIDIOC_STREAMON:
  572. v4l_dbg(1, cx25840_debug, client, "enable output\n");
  573. cx25840_write(client, 0x115, state->is_cx25836 ? 0x0c : 0x8c);
  574. cx25840_write(client, 0x116, state->is_cx25836 ? 0x04 : 0x07);
  575. break;
  576. case VIDIOC_STREAMOFF:
  577. v4l_dbg(1, cx25840_debug, client, "disable output\n");
  578. cx25840_write(client, 0x115, 0x00);
  579. cx25840_write(client, 0x116, 0x00);
  580. break;
  581. case VIDIOC_LOG_STATUS:
  582. log_video_status(client);
  583. if (!state->is_cx25836)
  584. log_audio_status(client);
  585. break;
  586. case VIDIOC_G_CTRL:
  587. return get_v4lctrl(client, (struct v4l2_control *)arg);
  588. case VIDIOC_S_CTRL:
  589. return set_v4lctrl(client, (struct v4l2_control *)arg);
  590. case VIDIOC_QUERYCTRL:
  591. {
  592. struct v4l2_queryctrl *qc = arg;
  593. switch (qc->id) {
  594. case V4L2_CID_BRIGHTNESS:
  595. case V4L2_CID_CONTRAST:
  596. case V4L2_CID_SATURATION:
  597. case V4L2_CID_HUE:
  598. return v4l2_ctrl_query_fill_std(qc);
  599. default:
  600. break;
  601. }
  602. if (state->is_cx25836)
  603. return -EINVAL;
  604. switch (qc->id) {
  605. case V4L2_CID_AUDIO_VOLUME:
  606. case V4L2_CID_AUDIO_MUTE:
  607. case V4L2_CID_AUDIO_BALANCE:
  608. case V4L2_CID_AUDIO_BASS:
  609. case V4L2_CID_AUDIO_TREBLE:
  610. return v4l2_ctrl_query_fill_std(qc);
  611. default:
  612. return -EINVAL;
  613. }
  614. return -EINVAL;
  615. }
  616. case VIDIOC_G_STD:
  617. *(v4l2_std_id *)arg = cx25840_get_v4lstd(client);
  618. break;
  619. case VIDIOC_S_STD:
  620. state->radio = 0;
  621. return set_v4lstd(client, *(v4l2_std_id *)arg);
  622. case AUDC_SET_RADIO:
  623. state->radio = 1;
  624. break;
  625. case VIDIOC_INT_G_VIDEO_ROUTING:
  626. route->input = state->vid_input;
  627. route->output = 0;
  628. break;
  629. case VIDIOC_INT_S_VIDEO_ROUTING:
  630. return set_input(client, route->input, state->aud_input);
  631. case VIDIOC_INT_G_AUDIO_ROUTING:
  632. if (state->is_cx25836)
  633. return -EINVAL;
  634. route->input = state->aud_input;
  635. route->output = 0;
  636. break;
  637. case VIDIOC_INT_S_AUDIO_ROUTING:
  638. if (state->is_cx25836)
  639. return -EINVAL;
  640. return set_input(client, state->vid_input, route->input);
  641. case VIDIOC_S_FREQUENCY:
  642. if (!state->is_cx25836) {
  643. input_change(client);
  644. }
  645. break;
  646. case VIDIOC_G_TUNER:
  647. {
  648. u8 vpres = cx25840_read(client, 0x40e) & 0x20;
  649. u8 mode;
  650. int val = 0;
  651. if (state->radio)
  652. break;
  653. vt->signal = vpres ? 0xffff : 0x0;
  654. if (state->is_cx25836)
  655. break;
  656. vt->capability |=
  657. V4L2_TUNER_CAP_STEREO | V4L2_TUNER_CAP_LANG1 |
  658. V4L2_TUNER_CAP_LANG2 | V4L2_TUNER_CAP_SAP;
  659. mode = cx25840_read(client, 0x804);
  660. /* get rxsubchans and audmode */
  661. if ((mode & 0xf) == 1)
  662. val |= V4L2_TUNER_SUB_STEREO;
  663. else
  664. val |= V4L2_TUNER_SUB_MONO;
  665. if (mode == 2 || mode == 4)
  666. val = V4L2_TUNER_SUB_LANG1 | V4L2_TUNER_SUB_LANG2;
  667. if (mode & 0x10)
  668. val |= V4L2_TUNER_SUB_SAP;
  669. vt->rxsubchans = val;
  670. vt->audmode = state->audmode;
  671. break;
  672. }
  673. case VIDIOC_S_TUNER:
  674. if (state->radio || state->is_cx25836)
  675. break;
  676. switch (vt->audmode) {
  677. case V4L2_TUNER_MODE_MONO:
  678. /* mono -> mono
  679. stereo -> mono
  680. bilingual -> lang1 */
  681. cx25840_and_or(client, 0x809, ~0xf, 0x00);
  682. break;
  683. case V4L2_TUNER_MODE_STEREO:
  684. case V4L2_TUNER_MODE_LANG1:
  685. /* mono -> mono
  686. stereo -> stereo
  687. bilingual -> lang1 */
  688. cx25840_and_or(client, 0x809, ~0xf, 0x04);
  689. break;
  690. case V4L2_TUNER_MODE_LANG1_LANG2:
  691. /* mono -> mono
  692. stereo -> stereo
  693. bilingual -> lang1/lang2 */
  694. cx25840_and_or(client, 0x809, ~0xf, 0x07);
  695. break;
  696. case V4L2_TUNER_MODE_LANG2:
  697. /* mono -> mono
  698. stereo -> stereo
  699. bilingual -> lang2 */
  700. cx25840_and_or(client, 0x809, ~0xf, 0x01);
  701. break;
  702. default:
  703. return -EINVAL;
  704. }
  705. state->audmode = vt->audmode;
  706. break;
  707. case VIDIOC_G_FMT:
  708. return get_v4lfmt(client, (struct v4l2_format *)arg);
  709. case VIDIOC_S_FMT:
  710. return set_v4lfmt(client, (struct v4l2_format *)arg);
  711. case VIDIOC_INT_RESET:
  712. if (state->is_cx25836)
  713. cx25836_initialize(client);
  714. else
  715. cx25840_initialize(client);
  716. break;
  717. case VIDIOC_G_CHIP_IDENT:
  718. return v4l2_chip_ident_i2c_client(client, arg, state->id, state->rev);
  719. default:
  720. return -EINVAL;
  721. }
  722. return 0;
  723. }
  724. /* ----------------------------------------------------------------------- */
  725. static struct i2c_driver i2c_driver_cx25840;
  726. static int cx25840_detect_client(struct i2c_adapter *adapter, int address,
  727. int kind)
  728. {
  729. struct i2c_client *client;
  730. struct cx25840_state *state;
  731. u32 id;
  732. u16 device_id;
  733. /* Check if the adapter supports the needed features
  734. * Not until kernel version 2.6.11 did the bit-algo
  735. * correctly report that it would do an I2C-level xfer */
  736. if (!i2c_check_functionality(adapter, I2C_FUNC_I2C))
  737. return 0;
  738. state = kzalloc(sizeof(struct cx25840_state), GFP_KERNEL);
  739. if (state == 0)
  740. return -ENOMEM;
  741. client = &state->c;
  742. client->addr = address;
  743. client->adapter = adapter;
  744. client->driver = &i2c_driver_cx25840;
  745. snprintf(client->name, sizeof(client->name) - 1, "cx25840");
  746. v4l_dbg(1, cx25840_debug, client, "detecting cx25840 client on address 0x%x\n", address << 1);
  747. device_id = cx25840_read(client, 0x101) << 8;
  748. device_id |= cx25840_read(client, 0x100);
  749. /* The high byte of the device ID should be
  750. * 0x83 for the cx2583x and 0x84 for the cx2584x */
  751. if ((device_id & 0xff00) == 0x8300) {
  752. id = V4L2_IDENT_CX25836 + ((device_id >> 4) & 0xf) - 6;
  753. state->is_cx25836 = 1;
  754. }
  755. else if ((device_id & 0xff00) == 0x8400) {
  756. id = V4L2_IDENT_CX25840 + ((device_id >> 4) & 0xf);
  757. state->is_cx25836 = 0;
  758. }
  759. else {
  760. v4l_dbg(1, cx25840_debug, client, "cx25840 not found\n");
  761. kfree(state);
  762. return 0;
  763. }
  764. /* Note: revision '(device_id & 0x0f) == 2' was never built. The
  765. marking skips from 0x1 == 22 to 0x3 == 23. */
  766. v4l_info(client, "cx25%3x-2%x found @ 0x%x (%s)\n",
  767. (device_id & 0xfff0) >> 4,
  768. (device_id & 0x0f) < 3 ? (device_id & 0x0f) + 1 : (device_id & 0x0f),
  769. address << 1, adapter->name);
  770. i2c_set_clientdata(client, state);
  771. state->vid_input = CX25840_COMPOSITE7;
  772. state->aud_input = CX25840_AUDIO8;
  773. state->audclk_freq = 48000;
  774. state->pvr150_workaround = 0;
  775. state->audmode = V4L2_TUNER_MODE_LANG1;
  776. state->unmute_volume = -1;
  777. state->vbi_line_offset = 8;
  778. state->id = id;
  779. state->rev = device_id;
  780. i2c_attach_client(client);
  781. return 0;
  782. }
  783. static int cx25840_attach_adapter(struct i2c_adapter *adapter)
  784. {
  785. if (adapter->class & I2C_CLASS_TV_ANALOG)
  786. return i2c_probe(adapter, &addr_data, &cx25840_detect_client);
  787. return 0;
  788. }
  789. static int cx25840_detach_client(struct i2c_client *client)
  790. {
  791. struct cx25840_state *state = i2c_get_clientdata(client);
  792. int err;
  793. err = i2c_detach_client(client);
  794. if (err) {
  795. return err;
  796. }
  797. kfree(state);
  798. return 0;
  799. }
  800. /* ----------------------------------------------------------------------- */
  801. static struct i2c_driver i2c_driver_cx25840 = {
  802. .driver = {
  803. .name = "cx25840",
  804. },
  805. .id = I2C_DRIVERID_CX25840,
  806. .attach_adapter = cx25840_attach_adapter,
  807. .detach_client = cx25840_detach_client,
  808. .command = cx25840_command,
  809. };
  810. static int __init m__init(void)
  811. {
  812. return i2c_add_driver(&i2c_driver_cx25840);
  813. }
  814. static void __exit m__exit(void)
  815. {
  816. i2c_del_driver(&i2c_driver_cx25840);
  817. }
  818. module_init(m__init);
  819. module_exit(m__exit);
  820. /* ----------------------------------------------------------------------- */
  821. static void log_video_status(struct i2c_client *client)
  822. {
  823. static const char *const fmt_strs[] = {
  824. "0x0",
  825. "NTSC-M", "NTSC-J", "NTSC-4.43",
  826. "PAL-BDGHI", "PAL-M", "PAL-N", "PAL-Nc", "PAL-60",
  827. "0x9", "0xA", "0xB",
  828. "SECAM",
  829. "0xD", "0xE", "0xF"
  830. };
  831. struct cx25840_state *state = i2c_get_clientdata(client);
  832. u8 vidfmt_sel = cx25840_read(client, 0x400) & 0xf;
  833. u8 gen_stat1 = cx25840_read(client, 0x40d);
  834. u8 gen_stat2 = cx25840_read(client, 0x40e);
  835. int vid_input = state->vid_input;
  836. v4l_info(client, "Video signal: %spresent\n",
  837. (gen_stat2 & 0x20) ? "" : "not ");
  838. v4l_info(client, "Detected format: %s\n",
  839. fmt_strs[gen_stat1 & 0xf]);
  840. v4l_info(client, "Specified standard: %s\n",
  841. vidfmt_sel ? fmt_strs[vidfmt_sel] : "automatic detection");
  842. if (vid_input >= CX25840_COMPOSITE1 &&
  843. vid_input <= CX25840_COMPOSITE8) {
  844. v4l_info(client, "Specified video input: Composite %d\n",
  845. vid_input - CX25840_COMPOSITE1 + 1);
  846. } else {
  847. v4l_info(client, "Specified video input: S-Video (Luma In%d, Chroma In%d)\n",
  848. (vid_input & 0xf0) >> 4, (vid_input & 0xf00) >> 8);
  849. }
  850. v4l_info(client, "Specified audioclock freq: %d Hz\n", state->audclk_freq);
  851. }
  852. /* ----------------------------------------------------------------------- */
  853. static void log_audio_status(struct i2c_client *client)
  854. {
  855. struct cx25840_state *state = i2c_get_clientdata(client);
  856. u8 download_ctl = cx25840_read(client, 0x803);
  857. u8 mod_det_stat0 = cx25840_read(client, 0x804);
  858. u8 mod_det_stat1 = cx25840_read(client, 0x805);
  859. u8 audio_config = cx25840_read(client, 0x808);
  860. u8 pref_mode = cx25840_read(client, 0x809);
  861. u8 afc0 = cx25840_read(client, 0x80b);
  862. u8 mute_ctl = cx25840_read(client, 0x8d3);
  863. int aud_input = state->aud_input;
  864. char *p;
  865. switch (mod_det_stat0) {
  866. case 0x00: p = "mono"; break;
  867. case 0x01: p = "stereo"; break;
  868. case 0x02: p = "dual"; break;
  869. case 0x04: p = "tri"; break;
  870. case 0x10: p = "mono with SAP"; break;
  871. case 0x11: p = "stereo with SAP"; break;
  872. case 0x12: p = "dual with SAP"; break;
  873. case 0x14: p = "tri with SAP"; break;
  874. case 0xfe: p = "forced mode"; break;
  875. default: p = "not defined";
  876. }
  877. v4l_info(client, "Detected audio mode: %s\n", p);
  878. switch (mod_det_stat1) {
  879. case 0x00: p = "not defined"; break;
  880. case 0x01: p = "EIAJ"; break;
  881. case 0x02: p = "A2-M"; break;
  882. case 0x03: p = "A2-BG"; break;
  883. case 0x04: p = "A2-DK1"; break;
  884. case 0x05: p = "A2-DK2"; break;
  885. case 0x06: p = "A2-DK3"; break;
  886. case 0x07: p = "A1 (6.0 MHz FM Mono)"; break;
  887. case 0x08: p = "AM-L"; break;
  888. case 0x09: p = "NICAM-BG"; break;
  889. case 0x0a: p = "NICAM-DK"; break;
  890. case 0x0b: p = "NICAM-I"; break;
  891. case 0x0c: p = "NICAM-L"; break;
  892. case 0x0d: p = "BTSC/EIAJ/A2-M Mono (4.5 MHz FMMono)"; break;
  893. case 0x0e: p = "IF FM Radio"; break;
  894. case 0x0f: p = "BTSC"; break;
  895. case 0x10: p = "high-deviation FM"; break;
  896. case 0x11: p = "very high-deviation FM"; break;
  897. case 0xfd: p = "unknown audio standard"; break;
  898. case 0xfe: p = "forced audio standard"; break;
  899. case 0xff: p = "no detected audio standard"; break;
  900. default: p = "not defined";
  901. }
  902. v4l_info(client, "Detected audio standard: %s\n", p);
  903. v4l_info(client, "Audio muted: %s\n",
  904. (state->unmute_volume >= 0) ? "yes" : "no");
  905. v4l_info(client, "Audio microcontroller: %s\n",
  906. (download_ctl & 0x10) ?
  907. ((mute_ctl & 0x2) ? "detecting" : "running") : "stopped");
  908. switch (audio_config >> 4) {
  909. case 0x00: p = "undefined"; break;
  910. case 0x01: p = "BTSC"; break;
  911. case 0x02: p = "EIAJ"; break;
  912. case 0x03: p = "A2-M"; break;
  913. case 0x04: p = "A2-BG"; break;
  914. case 0x05: p = "A2-DK1"; break;
  915. case 0x06: p = "A2-DK2"; break;
  916. case 0x07: p = "A2-DK3"; break;
  917. case 0x08: p = "A1 (6.0 MHz FM Mono)"; break;
  918. case 0x09: p = "AM-L"; break;
  919. case 0x0a: p = "NICAM-BG"; break;
  920. case 0x0b: p = "NICAM-DK"; break;
  921. case 0x0c: p = "NICAM-I"; break;
  922. case 0x0d: p = "NICAM-L"; break;
  923. case 0x0e: p = "FM radio"; break;
  924. case 0x0f: p = "automatic detection"; break;
  925. default: p = "undefined";
  926. }
  927. v4l_info(client, "Configured audio standard: %s\n", p);
  928. if ((audio_config >> 4) < 0xF) {
  929. switch (audio_config & 0xF) {
  930. case 0x00: p = "MONO1 (LANGUAGE A/Mono L+R channel for BTSC, EIAJ, A2)"; break;
  931. case 0x01: p = "MONO2 (LANGUAGE B)"; break;
  932. case 0x02: p = "MONO3 (STEREO forced MONO)"; break;
  933. case 0x03: p = "MONO4 (NICAM ANALOG-Language C/Analog Fallback)"; break;
  934. case 0x04: p = "STEREO"; break;
  935. case 0x05: p = "DUAL1 (AB)"; break;
  936. case 0x06: p = "DUAL2 (AC) (FM)"; break;
  937. case 0x07: p = "DUAL3 (BC) (FM)"; break;
  938. case 0x08: p = "DUAL4 (AC) (AM)"; break;
  939. case 0x09: p = "DUAL5 (BC) (AM)"; break;
  940. case 0x0a: p = "SAP"; break;
  941. default: p = "undefined";
  942. }
  943. v4l_info(client, "Configured audio mode: %s\n", p);
  944. } else {
  945. switch (audio_config & 0xF) {
  946. case 0x00: p = "BG"; break;
  947. case 0x01: p = "DK1"; break;
  948. case 0x02: p = "DK2"; break;
  949. case 0x03: p = "DK3"; break;
  950. case 0x04: p = "I"; break;
  951. case 0x05: p = "L"; break;
  952. case 0x06: p = "BTSC"; break;
  953. case 0x07: p = "EIAJ"; break;
  954. case 0x08: p = "A2-M"; break;
  955. case 0x09: p = "FM Radio"; break;
  956. case 0x0f: p = "automatic standard and mode detection"; break;
  957. default: p = "undefined";
  958. }
  959. v4l_info(client, "Configured audio system: %s\n", p);
  960. }
  961. if (aud_input) {
  962. v4l_info(client, "Specified audio input: Tuner (In%d)\n", aud_input);
  963. } else {
  964. v4l_info(client, "Specified audio input: External\n");
  965. }
  966. switch (pref_mode & 0xf) {
  967. case 0: p = "mono/language A"; break;
  968. case 1: p = "language B"; break;
  969. case 2: p = "language C"; break;
  970. case 3: p = "analog fallback"; break;
  971. case 4: p = "stereo"; break;
  972. case 5: p = "language AC"; break;
  973. case 6: p = "language BC"; break;
  974. case 7: p = "language AB"; break;
  975. default: p = "undefined";
  976. }
  977. v4l_info(client, "Preferred audio mode: %s\n", p);
  978. if ((audio_config & 0xf) == 0xf) {
  979. switch ((afc0 >> 3) & 0x3) {
  980. case 0: p = "system DK"; break;
  981. case 1: p = "system L"; break;
  982. case 2: p = "autodetect"; break;
  983. default: p = "undefined";
  984. }
  985. v4l_info(client, "Selected 65 MHz format: %s\n", p);
  986. switch (afc0 & 0x7) {
  987. case 0: p = "chroma"; break;
  988. case 1: p = "BTSC"; break;
  989. case 2: p = "EIAJ"; break;
  990. case 3: p = "A2-M"; break;
  991. case 4: p = "autodetect"; break;
  992. default: p = "undefined";
  993. }
  994. v4l_info(client, "Selected 45 MHz format: %s\n", p);
  995. }
  996. }