cx25840-core.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159
  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/cx25840.h>
  37. #include "cx25840-core.h"
  38. MODULE_DESCRIPTION("Conexant CX25840 audio/video decoder driver");
  39. MODULE_AUTHOR("Ulf Eklund, Chris Kennedy, Hans Verkuil, Tyler Trafford");
  40. MODULE_LICENSE("GPL");
  41. static unsigned short normal_i2c[] = { 0x88 >> 1, I2C_CLIENT_END };
  42. int cx25840_debug;
  43. module_param_named(debug,cx25840_debug, int, 0644);
  44. MODULE_PARM_DESC(debug, "Debugging messages [0=Off (default) 1=On]");
  45. I2C_CLIENT_INSMOD;
  46. /* ----------------------------------------------------------------------- */
  47. int cx25840_write(struct i2c_client *client, u16 addr, u8 value)
  48. {
  49. u8 buffer[3];
  50. buffer[0] = addr >> 8;
  51. buffer[1] = addr & 0xff;
  52. buffer[2] = value;
  53. return i2c_master_send(client, buffer, 3);
  54. }
  55. int cx25840_write4(struct i2c_client *client, u16 addr, u32 value)
  56. {
  57. u8 buffer[6];
  58. buffer[0] = addr >> 8;
  59. buffer[1] = addr & 0xff;
  60. buffer[2] = value >> 24;
  61. buffer[3] = (value >> 16) & 0xff;
  62. buffer[4] = (value >> 8) & 0xff;
  63. buffer[5] = value & 0xff;
  64. return i2c_master_send(client, buffer, 6);
  65. }
  66. u8 cx25840_read(struct i2c_client * client, u16 addr)
  67. {
  68. u8 buffer[2];
  69. buffer[0] = addr >> 8;
  70. buffer[1] = addr & 0xff;
  71. if (i2c_master_send(client, buffer, 2) < 2)
  72. return 0;
  73. if (i2c_master_recv(client, buffer, 1) < 1)
  74. return 0;
  75. return buffer[0];
  76. }
  77. u32 cx25840_read4(struct i2c_client * client, u16 addr)
  78. {
  79. u8 buffer[4];
  80. buffer[0] = addr >> 8;
  81. buffer[1] = addr & 0xff;
  82. if (i2c_master_send(client, buffer, 2) < 2)
  83. return 0;
  84. if (i2c_master_recv(client, buffer, 4) < 4)
  85. return 0;
  86. return (buffer[3] << 24) | (buffer[2] << 16) |
  87. (buffer[1] << 8) | buffer[0];
  88. }
  89. int cx25840_and_or(struct i2c_client *client, u16 addr, unsigned and_mask,
  90. u8 or_value)
  91. {
  92. return cx25840_write(client, addr,
  93. (cx25840_read(client, addr) & and_mask) |
  94. or_value);
  95. }
  96. /* ----------------------------------------------------------------------- */
  97. static int set_input(struct i2c_client *client, enum cx25840_video_input vid_input,
  98. enum cx25840_audio_input aud_input);
  99. static void log_audio_status(struct i2c_client *client);
  100. static void log_video_status(struct i2c_client *client);
  101. /* ----------------------------------------------------------------------- */
  102. static void init_dll1(struct i2c_client *client)
  103. {
  104. /* This is the Hauppauge sequence used to
  105. * initialize the Delay Lock Loop 1 (ADC DLL). */
  106. cx25840_write(client, 0x159, 0x23);
  107. cx25840_write(client, 0x15a, 0x87);
  108. cx25840_write(client, 0x15b, 0x06);
  109. cx25840_write(client, 0x159, 0xe1);
  110. cx25840_write(client, 0x15a, 0x86);
  111. cx25840_write(client, 0x159, 0xe0);
  112. cx25840_write(client, 0x159, 0xe1);
  113. cx25840_write(client, 0x15b, 0x10);
  114. }
  115. static void init_dll2(struct i2c_client *client)
  116. {
  117. /* This is the Hauppauge sequence used to
  118. * initialize the Delay Lock Loop 2 (ADC DLL). */
  119. cx25840_write(client, 0x15d, 0xe3);
  120. cx25840_write(client, 0x15e, 0x86);
  121. cx25840_write(client, 0x15f, 0x06);
  122. cx25840_write(client, 0x15d, 0xe1);
  123. cx25840_write(client, 0x15d, 0xe0);
  124. cx25840_write(client, 0x15d, 0xe1);
  125. }
  126. static void cx25836_initialize(struct i2c_client *client)
  127. {
  128. /* reset configuration is described on page 3-77 of the CX25836 datasheet */
  129. /* 2. */
  130. cx25840_and_or(client, 0x000, ~0x01, 0x01);
  131. cx25840_and_or(client, 0x000, ~0x01, 0x00);
  132. /* 3a. */
  133. cx25840_and_or(client, 0x15a, ~0x70, 0x00);
  134. /* 3b. */
  135. cx25840_and_or(client, 0x15b, ~0x1e, 0x06);
  136. /* 3c. */
  137. cx25840_and_or(client, 0x159, ~0x02, 0x02);
  138. /* 3d. */
  139. /* There should be a 10-us delay here, but since the
  140. i2c bus already has a 10-us delay we don't need to do
  141. anything */
  142. /* 3e. */
  143. cx25840_and_or(client, 0x159, ~0x02, 0x00);
  144. /* 3f. */
  145. cx25840_and_or(client, 0x159, ~0xc0, 0xc0);
  146. /* 3g. */
  147. cx25840_and_or(client, 0x159, ~0x01, 0x00);
  148. cx25840_and_or(client, 0x159, ~0x01, 0x01);
  149. /* 3h. */
  150. cx25840_and_or(client, 0x15b, ~0x1e, 0x10);
  151. }
  152. static void cx25840_initialize(struct i2c_client *client, int loadfw)
  153. {
  154. struct cx25840_state *state = i2c_get_clientdata(client);
  155. /* datasheet startup in numbered steps, refer to page 3-77 */
  156. /* 2. */
  157. cx25840_and_or(client, 0x803, ~0x10, 0x00);
  158. /* The default of this register should be 4, but I get 0 instead.
  159. * Set this register to 4 manually. */
  160. cx25840_write(client, 0x000, 0x04);
  161. /* 3. */
  162. init_dll1(client);
  163. init_dll2(client);
  164. cx25840_write(client, 0x136, 0x0a);
  165. /* 4. */
  166. cx25840_write(client, 0x13c, 0x01);
  167. cx25840_write(client, 0x13c, 0x00);
  168. /* 5. */
  169. if (loadfw)
  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_pal = !(cx25840_get_v4lstd(client) & V4L2_STD_NTSC);
  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_pal ? 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. switch (cmd) {
  534. #ifdef CONFIG_VIDEO_ADV_DEBUG
  535. /* ioctls to allow direct access to the
  536. * cx25840 registers for testing */
  537. case VIDIOC_INT_G_REGISTER:
  538. {
  539. struct v4l2_register *reg = arg;
  540. if (reg->i2c_id != I2C_DRIVERID_CX25840)
  541. return -EINVAL;
  542. reg->val = cx25840_read(client, reg->reg & 0x0fff);
  543. break;
  544. }
  545. case VIDIOC_INT_S_REGISTER:
  546. {
  547. struct v4l2_register *reg = arg;
  548. if (reg->i2c_id != I2C_DRIVERID_CX25840)
  549. return -EINVAL;
  550. if (!capable(CAP_SYS_ADMIN))
  551. return -EPERM;
  552. cx25840_write(client, reg->reg & 0x0fff, reg->val & 0xff);
  553. break;
  554. }
  555. #endif
  556. case VIDIOC_INT_DECODE_VBI_LINE:
  557. return cx25840_vbi(client, cmd, arg);
  558. case VIDIOC_INT_AUDIO_CLOCK_FREQ:
  559. return cx25840_audio(client, cmd, arg);
  560. case VIDIOC_STREAMON:
  561. v4l_dbg(1, cx25840_debug, client, "enable output\n");
  562. cx25840_write(client, 0x115, state->is_cx25836 ? 0x0c : 0x8c);
  563. cx25840_write(client, 0x116, state->is_cx25836 ? 0x04 : 0x07);
  564. break;
  565. case VIDIOC_STREAMOFF:
  566. v4l_dbg(1, cx25840_debug, client, "disable output\n");
  567. cx25840_write(client, 0x115, 0x00);
  568. cx25840_write(client, 0x116, 0x00);
  569. break;
  570. case VIDIOC_LOG_STATUS:
  571. log_video_status(client);
  572. if (!state->is_cx25836)
  573. log_audio_status(client);
  574. break;
  575. case VIDIOC_G_CTRL:
  576. return get_v4lctrl(client, (struct v4l2_control *)arg);
  577. case VIDIOC_S_CTRL:
  578. return set_v4lctrl(client, (struct v4l2_control *)arg);
  579. case VIDIOC_QUERYCTRL:
  580. {
  581. struct v4l2_queryctrl *qc = arg;
  582. switch (qc->id) {
  583. case V4L2_CID_BRIGHTNESS:
  584. case V4L2_CID_CONTRAST:
  585. case V4L2_CID_SATURATION:
  586. case V4L2_CID_HUE:
  587. return v4l2_ctrl_query_fill_std(qc);
  588. default:
  589. break;
  590. }
  591. if (state->is_cx25836)
  592. return -EINVAL;
  593. switch (qc->id) {
  594. case V4L2_CID_AUDIO_VOLUME:
  595. case V4L2_CID_AUDIO_MUTE:
  596. case V4L2_CID_AUDIO_BALANCE:
  597. case V4L2_CID_AUDIO_BASS:
  598. case V4L2_CID_AUDIO_TREBLE:
  599. return v4l2_ctrl_query_fill_std(qc);
  600. default:
  601. return -EINVAL;
  602. }
  603. return -EINVAL;
  604. }
  605. case VIDIOC_G_STD:
  606. *(v4l2_std_id *)arg = cx25840_get_v4lstd(client);
  607. break;
  608. case VIDIOC_S_STD:
  609. state->radio = 0;
  610. return set_v4lstd(client, *(v4l2_std_id *)arg);
  611. case AUDC_SET_RADIO:
  612. state->radio = 1;
  613. break;
  614. case VIDIOC_INT_G_VIDEO_ROUTING:
  615. route->input = state->vid_input;
  616. route->output = 0;
  617. break;
  618. case VIDIOC_INT_S_VIDEO_ROUTING:
  619. return set_input(client, route->input, state->aud_input);
  620. case VIDIOC_INT_G_AUDIO_ROUTING:
  621. if (state->is_cx25836)
  622. return -EINVAL;
  623. route->input = state->aud_input;
  624. route->output = 0;
  625. break;
  626. case VIDIOC_INT_S_AUDIO_ROUTING:
  627. if (state->is_cx25836)
  628. return -EINVAL;
  629. return set_input(client, state->vid_input, route->input);
  630. case VIDIOC_S_FREQUENCY:
  631. if (!state->is_cx25836) {
  632. input_change(client);
  633. }
  634. break;
  635. case VIDIOC_G_TUNER:
  636. {
  637. u8 vpres = cx25840_read(client, 0x40e) & 0x20;
  638. u8 mode;
  639. int val = 0;
  640. if (state->radio)
  641. break;
  642. vt->signal = vpres ? 0xffff : 0x0;
  643. if (state->is_cx25836)
  644. break;
  645. vt->capability |=
  646. V4L2_TUNER_CAP_STEREO | V4L2_TUNER_CAP_LANG1 |
  647. V4L2_TUNER_CAP_LANG2 | V4L2_TUNER_CAP_SAP;
  648. mode = cx25840_read(client, 0x804);
  649. /* get rxsubchans and audmode */
  650. if ((mode & 0xf) == 1)
  651. val |= V4L2_TUNER_SUB_STEREO;
  652. else
  653. val |= V4L2_TUNER_SUB_MONO;
  654. if (mode == 2 || mode == 4)
  655. val = V4L2_TUNER_SUB_LANG1 | V4L2_TUNER_SUB_LANG2;
  656. if (mode & 0x10)
  657. val |= V4L2_TUNER_SUB_SAP;
  658. vt->rxsubchans = val;
  659. vt->audmode = state->audmode;
  660. break;
  661. }
  662. case VIDIOC_S_TUNER:
  663. if (state->radio || state->is_cx25836)
  664. break;
  665. switch (vt->audmode) {
  666. case V4L2_TUNER_MODE_MONO:
  667. /* mono -> mono
  668. stereo -> mono
  669. bilingual -> lang1 */
  670. cx25840_and_or(client, 0x809, ~0xf, 0x00);
  671. break;
  672. case V4L2_TUNER_MODE_STEREO:
  673. case V4L2_TUNER_MODE_LANG1:
  674. /* mono -> mono
  675. stereo -> stereo
  676. bilingual -> lang1 */
  677. cx25840_and_or(client, 0x809, ~0xf, 0x04);
  678. break;
  679. case V4L2_TUNER_MODE_LANG1_LANG2:
  680. /* mono -> mono
  681. stereo -> stereo
  682. bilingual -> lang1/lang2 */
  683. cx25840_and_or(client, 0x809, ~0xf, 0x07);
  684. break;
  685. case V4L2_TUNER_MODE_LANG2:
  686. /* mono -> mono
  687. stereo -> stereo
  688. bilingual -> lang2 */
  689. cx25840_and_or(client, 0x809, ~0xf, 0x01);
  690. break;
  691. default:
  692. return -EINVAL;
  693. }
  694. state->audmode = vt->audmode;
  695. break;
  696. case VIDIOC_G_FMT:
  697. return get_v4lfmt(client, (struct v4l2_format *)arg);
  698. case VIDIOC_S_FMT:
  699. return set_v4lfmt(client, (struct v4l2_format *)arg);
  700. case VIDIOC_INT_RESET:
  701. if (state->is_cx25836)
  702. cx25836_initialize(client);
  703. else
  704. cx25840_initialize(client, 0);
  705. break;
  706. case VIDIOC_INT_G_CHIP_IDENT:
  707. *(enum v4l2_chip_ident *)arg = state->id;
  708. break;
  709. default:
  710. return -EINVAL;
  711. }
  712. return 0;
  713. }
  714. /* ----------------------------------------------------------------------- */
  715. static struct i2c_driver i2c_driver_cx25840;
  716. static int cx25840_detect_client(struct i2c_adapter *adapter, int address,
  717. int kind)
  718. {
  719. struct i2c_client *client;
  720. struct cx25840_state *state;
  721. enum v4l2_chip_ident id;
  722. u16 device_id;
  723. /* Check if the adapter supports the needed features
  724. * Not until kernel version 2.6.11 did the bit-algo
  725. * correctly report that it would do an I2C-level xfer */
  726. if (!i2c_check_functionality(adapter, I2C_FUNC_I2C))
  727. return 0;
  728. state = kzalloc(sizeof(struct cx25840_state), GFP_KERNEL);
  729. if (state == 0)
  730. return -ENOMEM;
  731. client = &state->c;
  732. client->addr = address;
  733. client->adapter = adapter;
  734. client->driver = &i2c_driver_cx25840;
  735. snprintf(client->name, sizeof(client->name) - 1, "cx25840");
  736. v4l_dbg(1, cx25840_debug, client, "detecting cx25840 client on address 0x%x\n", address << 1);
  737. device_id = cx25840_read(client, 0x101) << 8;
  738. device_id |= cx25840_read(client, 0x100);
  739. /* The high byte of the device ID should be
  740. * 0x83 for the cx2583x and 0x84 for the cx2584x */
  741. if ((device_id & 0xff00) == 0x8300) {
  742. id = V4L2_IDENT_CX25836 + ((device_id >> 4) & 0xf) - 6;
  743. state->is_cx25836 = 1;
  744. }
  745. else if ((device_id & 0xff00) == 0x8400) {
  746. id = V4L2_IDENT_CX25840 + ((device_id >> 4) & 0xf);
  747. state->is_cx25836 = 0;
  748. }
  749. else {
  750. v4l_dbg(1, cx25840_debug, client, "cx25840 not found\n");
  751. kfree(state);
  752. return 0;
  753. }
  754. v4l_info(client, "cx25%3x-2%x found @ 0x%x (%s)\n",
  755. (device_id & 0xfff0) >> 4,
  756. (device_id & 0x0f) < 3 ? (device_id & 0x0f) + 1 : 3,
  757. address << 1, adapter->name);
  758. i2c_set_clientdata(client, state);
  759. state->vid_input = CX25840_COMPOSITE7;
  760. state->aud_input = CX25840_AUDIO8;
  761. state->audclk_freq = 48000;
  762. state->pvr150_workaround = 0;
  763. state->audmode = V4L2_TUNER_MODE_LANG1;
  764. state->vbi_line_offset = 8;
  765. state->id = id;
  766. if (state->is_cx25836)
  767. cx25836_initialize(client);
  768. else
  769. cx25840_initialize(client, 1);
  770. i2c_attach_client(client);
  771. return 0;
  772. }
  773. static int cx25840_attach_adapter(struct i2c_adapter *adapter)
  774. {
  775. if (adapter->class & I2C_CLASS_TV_ANALOG)
  776. return i2c_probe(adapter, &addr_data, &cx25840_detect_client);
  777. return 0;
  778. }
  779. static int cx25840_detach_client(struct i2c_client *client)
  780. {
  781. struct cx25840_state *state = i2c_get_clientdata(client);
  782. int err;
  783. err = i2c_detach_client(client);
  784. if (err) {
  785. return err;
  786. }
  787. kfree(state);
  788. return 0;
  789. }
  790. /* ----------------------------------------------------------------------- */
  791. static struct i2c_driver i2c_driver_cx25840 = {
  792. .driver = {
  793. .name = "cx25840",
  794. },
  795. .id = I2C_DRIVERID_CX25840,
  796. .attach_adapter = cx25840_attach_adapter,
  797. .detach_client = cx25840_detach_client,
  798. .command = cx25840_command,
  799. };
  800. static int __init m__init(void)
  801. {
  802. return i2c_add_driver(&i2c_driver_cx25840);
  803. }
  804. static void __exit m__exit(void)
  805. {
  806. i2c_del_driver(&i2c_driver_cx25840);
  807. }
  808. module_init(m__init);
  809. module_exit(m__exit);
  810. /* ----------------------------------------------------------------------- */
  811. static void log_video_status(struct i2c_client *client)
  812. {
  813. static const char *const fmt_strs[] = {
  814. "0x0",
  815. "NTSC-M", "NTSC-J", "NTSC-4.43",
  816. "PAL-BDGHI", "PAL-M", "PAL-N", "PAL-Nc", "PAL-60",
  817. "0x9", "0xA", "0xB",
  818. "SECAM",
  819. "0xD", "0xE", "0xF"
  820. };
  821. struct cx25840_state *state = i2c_get_clientdata(client);
  822. u8 vidfmt_sel = cx25840_read(client, 0x400) & 0xf;
  823. u8 gen_stat1 = cx25840_read(client, 0x40d);
  824. u8 gen_stat2 = cx25840_read(client, 0x40e);
  825. int vid_input = state->vid_input;
  826. v4l_info(client, "Video signal: %spresent\n",
  827. (gen_stat2 & 0x20) ? "" : "not ");
  828. v4l_info(client, "Detected format: %s\n",
  829. fmt_strs[gen_stat1 & 0xf]);
  830. v4l_info(client, "Specified standard: %s\n",
  831. vidfmt_sel ? fmt_strs[vidfmt_sel] : "automatic detection");
  832. if (vid_input >= CX25840_COMPOSITE1 &&
  833. vid_input <= CX25840_COMPOSITE8) {
  834. v4l_info(client, "Specified video input: Composite %d\n",
  835. vid_input - CX25840_COMPOSITE1 + 1);
  836. } else {
  837. v4l_info(client, "Specified video input: S-Video (Luma In%d, Chroma In%d)\n",
  838. (vid_input & 0xf0) >> 4, (vid_input & 0xf00) >> 8);
  839. }
  840. v4l_info(client, "Specified audioclock freq: %d Hz\n", state->audclk_freq);
  841. }
  842. /* ----------------------------------------------------------------------- */
  843. static void log_audio_status(struct i2c_client *client)
  844. {
  845. struct cx25840_state *state = i2c_get_clientdata(client);
  846. u8 download_ctl = cx25840_read(client, 0x803);
  847. u8 mod_det_stat0 = cx25840_read(client, 0x804);
  848. u8 mod_det_stat1 = cx25840_read(client, 0x805);
  849. u8 audio_config = cx25840_read(client, 0x808);
  850. u8 pref_mode = cx25840_read(client, 0x809);
  851. u8 afc0 = cx25840_read(client, 0x80b);
  852. u8 mute_ctl = cx25840_read(client, 0x8d3);
  853. int aud_input = state->aud_input;
  854. char *p;
  855. switch (mod_det_stat0) {
  856. case 0x00: p = "mono"; break;
  857. case 0x01: p = "stereo"; break;
  858. case 0x02: p = "dual"; break;
  859. case 0x04: p = "tri"; break;
  860. case 0x10: p = "mono with SAP"; break;
  861. case 0x11: p = "stereo with SAP"; break;
  862. case 0x12: p = "dual with SAP"; break;
  863. case 0x14: p = "tri with SAP"; break;
  864. case 0xfe: p = "forced mode"; break;
  865. default: p = "not defined";
  866. }
  867. v4l_info(client, "Detected audio mode: %s\n", p);
  868. switch (mod_det_stat1) {
  869. case 0x00: p = "not defined"; break;
  870. case 0x01: p = "EIAJ"; break;
  871. case 0x02: p = "A2-M"; break;
  872. case 0x03: p = "A2-BG"; break;
  873. case 0x04: p = "A2-DK1"; break;
  874. case 0x05: p = "A2-DK2"; break;
  875. case 0x06: p = "A2-DK3"; break;
  876. case 0x07: p = "A1 (6.0 MHz FM Mono)"; break;
  877. case 0x08: p = "AM-L"; break;
  878. case 0x09: p = "NICAM-BG"; break;
  879. case 0x0a: p = "NICAM-DK"; break;
  880. case 0x0b: p = "NICAM-I"; break;
  881. case 0x0c: p = "NICAM-L"; break;
  882. case 0x0d: p = "BTSC/EIAJ/A2-M Mono (4.5 MHz FMMono)"; break;
  883. case 0x0e: p = "IF FM Radio"; break;
  884. case 0x0f: p = "BTSC"; break;
  885. case 0x10: p = "high-deviation FM"; break;
  886. case 0x11: p = "very high-deviation FM"; break;
  887. case 0xfd: p = "unknown audio standard"; break;
  888. case 0xfe: p = "forced audio standard"; break;
  889. case 0xff: p = "no detected audio standard"; break;
  890. default: p = "not defined";
  891. }
  892. v4l_info(client, "Detected audio standard: %s\n", p);
  893. v4l_info(client, "Audio muted: %s\n",
  894. (mute_ctl & 0x2) ? "yes" : "no");
  895. v4l_info(client, "Audio microcontroller: %s\n",
  896. (download_ctl & 0x10) ? "running" : "stopped");
  897. switch (audio_config >> 4) {
  898. case 0x00: p = "undefined"; break;
  899. case 0x01: p = "BTSC"; break;
  900. case 0x02: p = "EIAJ"; break;
  901. case 0x03: p = "A2-M"; break;
  902. case 0x04: p = "A2-BG"; break;
  903. case 0x05: p = "A2-DK1"; break;
  904. case 0x06: p = "A2-DK2"; break;
  905. case 0x07: p = "A2-DK3"; break;
  906. case 0x08: p = "A1 (6.0 MHz FM Mono)"; break;
  907. case 0x09: p = "AM-L"; break;
  908. case 0x0a: p = "NICAM-BG"; break;
  909. case 0x0b: p = "NICAM-DK"; break;
  910. case 0x0c: p = "NICAM-I"; break;
  911. case 0x0d: p = "NICAM-L"; break;
  912. case 0x0e: p = "FM radio"; break;
  913. case 0x0f: p = "automatic detection"; break;
  914. default: p = "undefined";
  915. }
  916. v4l_info(client, "Configured audio standard: %s\n", p);
  917. if ((audio_config >> 4) < 0xF) {
  918. switch (audio_config & 0xF) {
  919. case 0x00: p = "MONO1 (LANGUAGE A/Mono L+R channel for BTSC, EIAJ, A2)"; break;
  920. case 0x01: p = "MONO2 (LANGUAGE B)"; break;
  921. case 0x02: p = "MONO3 (STEREO forced MONO)"; break;
  922. case 0x03: p = "MONO4 (NICAM ANALOG-Language C/Analog Fallback)"; break;
  923. case 0x04: p = "STEREO"; break;
  924. case 0x05: p = "DUAL1 (AB)"; break;
  925. case 0x06: p = "DUAL2 (AC) (FM)"; break;
  926. case 0x07: p = "DUAL3 (BC) (FM)"; break;
  927. case 0x08: p = "DUAL4 (AC) (AM)"; break;
  928. case 0x09: p = "DUAL5 (BC) (AM)"; break;
  929. case 0x0a: p = "SAP"; break;
  930. default: p = "undefined";
  931. }
  932. v4l_info(client, "Configured audio mode: %s\n", p);
  933. } else {
  934. switch (audio_config & 0xF) {
  935. case 0x00: p = "BG"; break;
  936. case 0x01: p = "DK1"; break;
  937. case 0x02: p = "DK2"; break;
  938. case 0x03: p = "DK3"; break;
  939. case 0x04: p = "I"; break;
  940. case 0x05: p = "L"; break;
  941. case 0x06: p = "BTSC"; break;
  942. case 0x07: p = "EIAJ"; break;
  943. case 0x08: p = "A2-M"; break;
  944. case 0x09: p = "FM Radio"; break;
  945. case 0x0f: p = "automatic standard and mode detection"; break;
  946. default: p = "undefined";
  947. }
  948. v4l_info(client, "Configured audio system: %s\n", p);
  949. }
  950. if (aud_input) {
  951. v4l_info(client, "Specified audio input: Tuner (In%d)\n", aud_input);
  952. } else {
  953. v4l_info(client, "Specified audio input: External\n");
  954. }
  955. switch (pref_mode & 0xf) {
  956. case 0: p = "mono/language A"; break;
  957. case 1: p = "language B"; break;
  958. case 2: p = "language C"; break;
  959. case 3: p = "analog fallback"; break;
  960. case 4: p = "stereo"; break;
  961. case 5: p = "language AC"; break;
  962. case 6: p = "language BC"; break;
  963. case 7: p = "language AB"; break;
  964. default: p = "undefined";
  965. }
  966. v4l_info(client, "Preferred audio mode: %s\n", p);
  967. if ((audio_config & 0xf) == 0xf) {
  968. switch ((afc0 >> 3) & 0x3) {
  969. case 0: p = "system DK"; break;
  970. case 1: p = "system L"; break;
  971. case 2: p = "autodetect"; break;
  972. default: p = "undefined";
  973. }
  974. v4l_info(client, "Selected 65 MHz format: %s\n", p);
  975. switch (afc0 & 0x7) {
  976. case 0: p = "chroma"; break;
  977. case 1: p = "BTSC"; break;
  978. case 2: p = "EIAJ"; break;
  979. case 3: p = "A2-M"; break;
  980. case 4: p = "autodetect"; break;
  981. default: p = "undefined";
  982. }
  983. v4l_info(client, "Selected 45 MHz format: %s\n", p);
  984. }
  985. }