cx25840-core.c 32 KB

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