tda9887.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650
  1. #include <linux/module.h>
  2. #include <linux/kernel.h>
  3. #include <linux/i2c.h>
  4. #include <linux/types.h>
  5. #include <linux/init.h>
  6. #include <linux/errno.h>
  7. #include <linux/slab.h>
  8. #include <linux/delay.h>
  9. #include <linux/videodev.h>
  10. #include <media/v4l2-common.h>
  11. #include <media/tuner.h>
  12. #include "tuner-driver.h"
  13. /* Chips:
  14. TDA9885 (PAL, NTSC)
  15. TDA9886 (PAL, SECAM, NTSC)
  16. TDA9887 (PAL, SECAM, NTSC, FM Radio)
  17. Used as part of several tuners
  18. */
  19. #define tda9887_info(fmt, arg...) do {\
  20. printk(KERN_INFO "%s %d-%04x: " fmt, t->i2c.name, \
  21. i2c_adapter_id(t->i2c.adapter), t->i2c.addr , ##arg); } while (0)
  22. #define tda9887_dbg(fmt, arg...) do {\
  23. if (tuner_debug) \
  24. printk(KERN_INFO "%s %d-%04x: " fmt, t->i2c.name, \
  25. i2c_adapter_id(t->i2c.adapter), t->i2c.addr , ##arg); } while (0)
  26. struct tda9887_priv {
  27. struct tuner_i2c_props i2c_props;
  28. unsigned char data[4];
  29. };
  30. /* ---------------------------------------------------------------------- */
  31. #define UNSET (-1U)
  32. struct tvnorm {
  33. v4l2_std_id std;
  34. char *name;
  35. unsigned char b;
  36. unsigned char c;
  37. unsigned char e;
  38. };
  39. /* ---------------------------------------------------------------------- */
  40. //
  41. // TDA defines
  42. //
  43. //// first reg (b)
  44. #define cVideoTrapBypassOFF 0x00 // bit b0
  45. #define cVideoTrapBypassON 0x01 // bit b0
  46. #define cAutoMuteFmInactive 0x00 // bit b1
  47. #define cAutoMuteFmActive 0x02 // bit b1
  48. #define cIntercarrier 0x00 // bit b2
  49. #define cQSS 0x04 // bit b2
  50. #define cPositiveAmTV 0x00 // bit b3:4
  51. #define cFmRadio 0x08 // bit b3:4
  52. #define cNegativeFmTV 0x10 // bit b3:4
  53. #define cForcedMuteAudioON 0x20 // bit b5
  54. #define cForcedMuteAudioOFF 0x00 // bit b5
  55. #define cOutputPort1Active 0x00 // bit b6
  56. #define cOutputPort1Inactive 0x40 // bit b6
  57. #define cOutputPort2Active 0x00 // bit b7
  58. #define cOutputPort2Inactive 0x80 // bit b7
  59. //// second reg (c)
  60. #define cDeemphasisOFF 0x00 // bit c5
  61. #define cDeemphasisON 0x20 // bit c5
  62. #define cDeemphasis75 0x00 // bit c6
  63. #define cDeemphasis50 0x40 // bit c6
  64. #define cAudioGain0 0x00 // bit c7
  65. #define cAudioGain6 0x80 // bit c7
  66. #define cTopMask 0x1f // bit c0:4
  67. #define cTopDefault 0x10 // bit c0:4
  68. //// third reg (e)
  69. #define cAudioIF_4_5 0x00 // bit e0:1
  70. #define cAudioIF_5_5 0x01 // bit e0:1
  71. #define cAudioIF_6_0 0x02 // bit e0:1
  72. #define cAudioIF_6_5 0x03 // bit e0:1
  73. #define cVideoIFMask 0x1c // bit e2:4
  74. /* Video IF selection in TV Mode (bit B3=0) */
  75. #define cVideoIF_58_75 0x00 // bit e2:4
  76. #define cVideoIF_45_75 0x04 // bit e2:4
  77. #define cVideoIF_38_90 0x08 // bit e2:4
  78. #define cVideoIF_38_00 0x0C // bit e2:4
  79. #define cVideoIF_33_90 0x10 // bit e2:4
  80. #define cVideoIF_33_40 0x14 // bit e2:4
  81. #define cRadioIF_45_75 0x18 // bit e2:4
  82. #define cRadioIF_38_90 0x1C // bit e2:4
  83. /* IF1 selection in Radio Mode (bit B3=1) */
  84. #define cRadioIF_33_30 0x00 // bit e2,4 (also 0x10,0x14)
  85. #define cRadioIF_41_30 0x04 // bit e2,4
  86. /* Output of AFC pin in radio mode when bit E7=1 */
  87. #define cRadioAGC_SIF 0x00 // bit e3
  88. #define cRadioAGC_FM 0x08 // bit e3
  89. #define cTunerGainNormal 0x00 // bit e5
  90. #define cTunerGainLow 0x20 // bit e5
  91. #define cGating_18 0x00 // bit e6
  92. #define cGating_36 0x40 // bit e6
  93. #define cAgcOutON 0x80 // bit e7
  94. #define cAgcOutOFF 0x00 // bit e7
  95. /* ---------------------------------------------------------------------- */
  96. static struct tvnorm tvnorms[] = {
  97. {
  98. .std = V4L2_STD_PAL_BG | V4L2_STD_PAL_H | V4L2_STD_PAL_N,
  99. .name = "PAL-BGHN",
  100. .b = ( cNegativeFmTV |
  101. cQSS ),
  102. .c = ( cDeemphasisON |
  103. cDeemphasis50 |
  104. cTopDefault),
  105. .e = ( cGating_36 |
  106. cAudioIF_5_5 |
  107. cVideoIF_38_90 ),
  108. },{
  109. .std = V4L2_STD_PAL_I,
  110. .name = "PAL-I",
  111. .b = ( cNegativeFmTV |
  112. cQSS ),
  113. .c = ( cDeemphasisON |
  114. cDeemphasis50 |
  115. cTopDefault),
  116. .e = ( cGating_36 |
  117. cAudioIF_6_0 |
  118. cVideoIF_38_90 ),
  119. },{
  120. .std = V4L2_STD_PAL_DK,
  121. .name = "PAL-DK",
  122. .b = ( cNegativeFmTV |
  123. cQSS ),
  124. .c = ( cDeemphasisON |
  125. cDeemphasis50 |
  126. cTopDefault),
  127. .e = ( cGating_36 |
  128. cAudioIF_6_5 |
  129. cVideoIF_38_90 ),
  130. },{
  131. .std = V4L2_STD_PAL_M | V4L2_STD_PAL_Nc,
  132. .name = "PAL-M/Nc",
  133. .b = ( cNegativeFmTV |
  134. cQSS ),
  135. .c = ( cDeemphasisON |
  136. cDeemphasis75 |
  137. cTopDefault),
  138. .e = ( cGating_36 |
  139. cAudioIF_4_5 |
  140. cVideoIF_45_75 ),
  141. },{
  142. .std = V4L2_STD_SECAM_B | V4L2_STD_SECAM_G | V4L2_STD_SECAM_H,
  143. .name = "SECAM-BGH",
  144. .b = ( cPositiveAmTV |
  145. cQSS ),
  146. .c = ( cTopDefault),
  147. .e = ( cGating_36 |
  148. cAudioIF_5_5 |
  149. cVideoIF_38_90 ),
  150. },{
  151. .std = V4L2_STD_SECAM_L,
  152. .name = "SECAM-L",
  153. .b = ( cPositiveAmTV |
  154. cQSS ),
  155. .c = ( cTopDefault),
  156. .e = ( cGating_36 |
  157. cAudioIF_6_5 |
  158. cVideoIF_38_90 ),
  159. },{
  160. .std = V4L2_STD_SECAM_LC,
  161. .name = "SECAM-L'",
  162. .b = ( cOutputPort2Inactive |
  163. cPositiveAmTV |
  164. cQSS ),
  165. .c = ( cTopDefault),
  166. .e = ( cGating_36 |
  167. cAudioIF_6_5 |
  168. cVideoIF_33_90 ),
  169. },{
  170. .std = V4L2_STD_SECAM_DK,
  171. .name = "SECAM-DK",
  172. .b = ( cNegativeFmTV |
  173. cQSS ),
  174. .c = ( cDeemphasisON |
  175. cDeemphasis50 |
  176. cTopDefault),
  177. .e = ( cGating_36 |
  178. cAudioIF_6_5 |
  179. cVideoIF_38_90 ),
  180. },{
  181. .std = V4L2_STD_NTSC_M | V4L2_STD_NTSC_M_KR,
  182. .name = "NTSC-M",
  183. .b = ( cNegativeFmTV |
  184. cQSS ),
  185. .c = ( cDeemphasisON |
  186. cDeemphasis75 |
  187. cTopDefault),
  188. .e = ( cGating_36 |
  189. cAudioIF_4_5 |
  190. cVideoIF_45_75 ),
  191. },{
  192. .std = V4L2_STD_NTSC_M_JP,
  193. .name = "NTSC-M-JP",
  194. .b = ( cNegativeFmTV |
  195. cQSS ),
  196. .c = ( cDeemphasisON |
  197. cDeemphasis50 |
  198. cTopDefault),
  199. .e = ( cGating_36 |
  200. cAudioIF_4_5 |
  201. cVideoIF_58_75 ),
  202. }
  203. };
  204. static struct tvnorm radio_stereo = {
  205. .name = "Radio Stereo",
  206. .b = ( cFmRadio |
  207. cQSS ),
  208. .c = ( cDeemphasisOFF |
  209. cAudioGain6 |
  210. cTopDefault),
  211. .e = ( cTunerGainLow |
  212. cAudioIF_5_5 |
  213. cRadioIF_38_90 ),
  214. };
  215. static struct tvnorm radio_mono = {
  216. .name = "Radio Mono",
  217. .b = ( cFmRadio |
  218. cQSS ),
  219. .c = ( cDeemphasisON |
  220. cDeemphasis75 |
  221. cTopDefault),
  222. .e = ( cTunerGainLow |
  223. cAudioIF_5_5 |
  224. cRadioIF_38_90 ),
  225. };
  226. /* ---------------------------------------------------------------------- */
  227. static void dump_read_message(struct tuner *t, unsigned char *buf)
  228. {
  229. static char *afc[16] = {
  230. "- 12.5 kHz",
  231. "- 37.5 kHz",
  232. "- 62.5 kHz",
  233. "- 87.5 kHz",
  234. "-112.5 kHz",
  235. "-137.5 kHz",
  236. "-162.5 kHz",
  237. "-187.5 kHz [min]",
  238. "+187.5 kHz [max]",
  239. "+162.5 kHz",
  240. "+137.5 kHz",
  241. "+112.5 kHz",
  242. "+ 87.5 kHz",
  243. "+ 62.5 kHz",
  244. "+ 37.5 kHz",
  245. "+ 12.5 kHz",
  246. };
  247. tda9887_info("read: 0x%2x\n", buf[0]);
  248. tda9887_info(" after power on : %s\n", (buf[0] & 0x01) ? "yes" : "no");
  249. tda9887_info(" afc : %s\n", afc[(buf[0] >> 1) & 0x0f]);
  250. tda9887_info(" fmif level : %s\n", (buf[0] & 0x20) ? "high" : "low");
  251. tda9887_info(" afc window : %s\n", (buf[0] & 0x40) ? "in" : "out");
  252. tda9887_info(" vfi level : %s\n", (buf[0] & 0x80) ? "high" : "low");
  253. }
  254. static void dump_write_message(struct tuner *t, unsigned char *buf)
  255. {
  256. static char *sound[4] = {
  257. "AM/TV",
  258. "FM/radio",
  259. "FM/TV",
  260. "FM/radio"
  261. };
  262. static char *adjust[32] = {
  263. "-16", "-15", "-14", "-13", "-12", "-11", "-10", "-9",
  264. "-8", "-7", "-6", "-5", "-4", "-3", "-2", "-1",
  265. "0", "+1", "+2", "+3", "+4", "+5", "+6", "+7",
  266. "+8", "+9", "+10", "+11", "+12", "+13", "+14", "+15"
  267. };
  268. static char *deemph[4] = {
  269. "no", "no", "75", "50"
  270. };
  271. static char *carrier[4] = {
  272. "4.5 MHz",
  273. "5.5 MHz",
  274. "6.0 MHz",
  275. "6.5 MHz / AM"
  276. };
  277. static char *vif[8] = {
  278. "58.75 MHz",
  279. "45.75 MHz",
  280. "38.9 MHz",
  281. "38.0 MHz",
  282. "33.9 MHz",
  283. "33.4 MHz",
  284. "45.75 MHz + pin13",
  285. "38.9 MHz + pin13",
  286. };
  287. static char *rif[4] = {
  288. "44 MHz",
  289. "52 MHz",
  290. "52 MHz",
  291. "44 MHz",
  292. };
  293. tda9887_info("write: byte B 0x%02x\n",buf[1]);
  294. tda9887_info(" B0 video mode : %s\n",
  295. (buf[1] & 0x01) ? "video trap" : "sound trap");
  296. tda9887_info(" B1 auto mute fm : %s\n",
  297. (buf[1] & 0x02) ? "yes" : "no");
  298. tda9887_info(" B2 carrier mode : %s\n",
  299. (buf[1] & 0x04) ? "QSS" : "Intercarrier");
  300. tda9887_info(" B3-4 tv sound/radio : %s\n",
  301. sound[(buf[1] & 0x18) >> 3]);
  302. tda9887_info(" B5 force mute audio: %s\n",
  303. (buf[1] & 0x20) ? "yes" : "no");
  304. tda9887_info(" B6 output port 1 : %s\n",
  305. (buf[1] & 0x40) ? "high (inactive)" : "low (active)");
  306. tda9887_info(" B7 output port 2 : %s\n",
  307. (buf[1] & 0x80) ? "high (inactive)" : "low (active)");
  308. tda9887_info("write: byte C 0x%02x\n",buf[2]);
  309. tda9887_info(" C0-4 top adjustment : %s dB\n", adjust[buf[2] & 0x1f]);
  310. tda9887_info(" C5-6 de-emphasis : %s\n", deemph[(buf[2] & 0x60) >> 5]);
  311. tda9887_info(" C7 audio gain : %s\n",
  312. (buf[2] & 0x80) ? "-6" : "0");
  313. tda9887_info("write: byte E 0x%02x\n",buf[3]);
  314. tda9887_info(" E0-1 sound carrier : %s\n",
  315. carrier[(buf[3] & 0x03)]);
  316. tda9887_info(" E6 l pll gating : %s\n",
  317. (buf[3] & 0x40) ? "36" : "13");
  318. if (buf[1] & 0x08) {
  319. /* radio */
  320. tda9887_info(" E2-4 video if : %s\n",
  321. rif[(buf[3] & 0x0c) >> 2]);
  322. tda9887_info(" E7 vif agc output : %s\n",
  323. (buf[3] & 0x80)
  324. ? ((buf[3] & 0x10) ? "fm-agc radio" : "sif-agc radio")
  325. : "fm radio carrier afc");
  326. } else {
  327. /* video */
  328. tda9887_info(" E2-4 video if : %s\n",
  329. vif[(buf[3] & 0x1c) >> 2]);
  330. tda9887_info(" E5 tuner gain : %s\n",
  331. (buf[3] & 0x80)
  332. ? ((buf[3] & 0x20) ? "external" : "normal")
  333. : ((buf[3] & 0x20) ? "minimum" : "normal"));
  334. tda9887_info(" E7 vif agc output : %s\n",
  335. (buf[3] & 0x80)
  336. ? ((buf[3] & 0x20)
  337. ? "pin3 port, pin22 vif agc out"
  338. : "pin22 port, pin3 vif acg ext in")
  339. : "pin3+pin22 port");
  340. }
  341. tda9887_info("--\n");
  342. }
  343. /* ---------------------------------------------------------------------- */
  344. static int tda9887_set_tvnorm(struct tuner *t, char *buf)
  345. {
  346. struct tvnorm *norm = NULL;
  347. int i;
  348. if (t->mode == V4L2_TUNER_RADIO) {
  349. if (t->audmode == V4L2_TUNER_MODE_MONO)
  350. norm = &radio_mono;
  351. else
  352. norm = &radio_stereo;
  353. } else {
  354. for (i = 0; i < ARRAY_SIZE(tvnorms); i++) {
  355. if (tvnorms[i].std & t->std) {
  356. norm = tvnorms+i;
  357. break;
  358. }
  359. }
  360. }
  361. if (NULL == norm) {
  362. tda9887_dbg("Unsupported tvnorm entry - audio muted\n");
  363. return -1;
  364. }
  365. tda9887_dbg("configure for: %s\n",norm->name);
  366. buf[1] = norm->b;
  367. buf[2] = norm->c;
  368. buf[3] = norm->e;
  369. return 0;
  370. }
  371. static unsigned int port1 = UNSET;
  372. static unsigned int port2 = UNSET;
  373. static unsigned int qss = UNSET;
  374. static unsigned int adjust = UNSET;
  375. module_param(port1, int, 0644);
  376. module_param(port2, int, 0644);
  377. module_param(qss, int, 0644);
  378. module_param(adjust, int, 0644);
  379. static int tda9887_set_insmod(struct tuner *t, char *buf)
  380. {
  381. if (UNSET != port1) {
  382. if (port1)
  383. buf[1] |= cOutputPort1Inactive;
  384. else
  385. buf[1] &= ~cOutputPort1Inactive;
  386. }
  387. if (UNSET != port2) {
  388. if (port2)
  389. buf[1] |= cOutputPort2Inactive;
  390. else
  391. buf[1] &= ~cOutputPort2Inactive;
  392. }
  393. if (UNSET != qss) {
  394. if (qss)
  395. buf[1] |= cQSS;
  396. else
  397. buf[1] &= ~cQSS;
  398. }
  399. if (adjust >= 0x00 && adjust < 0x20) {
  400. buf[2] &= ~cTopMask;
  401. buf[2] |= adjust;
  402. }
  403. return 0;
  404. }
  405. static int tda9887_set_config(struct tuner *t, char *buf)
  406. {
  407. if (t->tda9887_config & TDA9887_PORT1_ACTIVE)
  408. buf[1] &= ~cOutputPort1Inactive;
  409. if (t->tda9887_config & TDA9887_PORT1_INACTIVE)
  410. buf[1] |= cOutputPort1Inactive;
  411. if (t->tda9887_config & TDA9887_PORT2_ACTIVE)
  412. buf[1] &= ~cOutputPort2Inactive;
  413. if (t->tda9887_config & TDA9887_PORT2_INACTIVE)
  414. buf[1] |= cOutputPort2Inactive;
  415. if (t->tda9887_config & TDA9887_QSS)
  416. buf[1] |= cQSS;
  417. if (t->tda9887_config & TDA9887_INTERCARRIER)
  418. buf[1] &= ~cQSS;
  419. if (t->tda9887_config & TDA9887_AUTOMUTE)
  420. buf[1] |= cAutoMuteFmActive;
  421. if (t->tda9887_config & TDA9887_DEEMPHASIS_MASK) {
  422. buf[2] &= ~0x60;
  423. switch (t->tda9887_config & TDA9887_DEEMPHASIS_MASK) {
  424. case TDA9887_DEEMPHASIS_NONE:
  425. buf[2] |= cDeemphasisOFF;
  426. break;
  427. case TDA9887_DEEMPHASIS_50:
  428. buf[2] |= cDeemphasisON | cDeemphasis50;
  429. break;
  430. case TDA9887_DEEMPHASIS_75:
  431. buf[2] |= cDeemphasisON | cDeemphasis75;
  432. break;
  433. }
  434. }
  435. if (t->tda9887_config & TDA9887_TOP_SET) {
  436. buf[2] &= ~cTopMask;
  437. buf[2] |= (t->tda9887_config >> 8) & cTopMask;
  438. }
  439. if ((t->tda9887_config & TDA9887_INTERCARRIER_NTSC) && (t->std & V4L2_STD_NTSC))
  440. buf[1] &= ~cQSS;
  441. if (t->tda9887_config & TDA9887_GATING_18)
  442. buf[3] &= ~cGating_36;
  443. if (t->mode == V4L2_TUNER_RADIO) {
  444. if (t->tda9887_config & TDA9887_RIF_41_3) {
  445. buf[3] &= ~cVideoIFMask;
  446. buf[3] |= cRadioIF_41_30;
  447. }
  448. if (t->tda9887_config & TDA9887_GAIN_NORMAL)
  449. buf[3] &= ~cTunerGainLow;
  450. }
  451. return 0;
  452. }
  453. /* ---------------------------------------------------------------------- */
  454. static int tda9887_status(struct tuner *t)
  455. {
  456. struct tda9887_priv *priv = t->priv;
  457. unsigned char buf[1];
  458. int rc;
  459. memset(buf,0,sizeof(buf));
  460. if (1 != (rc = tuner_i2c_xfer_recv(&priv->i2c_props,buf,1)))
  461. tda9887_info("i2c i/o error: rc == %d (should be 1)\n",rc);
  462. dump_read_message(t, buf);
  463. return 0;
  464. }
  465. static void tda9887_configure(struct tuner *t)
  466. {
  467. struct tda9887_priv *priv = t->priv;
  468. int rc;
  469. memset(priv->data,0,sizeof(priv->data));
  470. tda9887_set_tvnorm(t,priv->data);
  471. /* A note on the port settings:
  472. These settings tend to depend on the specifics of the board.
  473. By default they are set to inactive (bit value 1) by this driver,
  474. overwriting any changes made by the tvnorm. This means that it
  475. is the responsibility of the module using the tda9887 to set
  476. these values in case of changes in the tvnorm.
  477. In many cases port 2 should be made active (0) when selecting
  478. SECAM-L, and port 2 should remain inactive (1) for SECAM-L'.
  479. For the other standards the tda9887 application note says that
  480. the ports should be set to active (0), but, again, that may
  481. differ depending on the precise hardware configuration.
  482. */
  483. priv->data[1] |= cOutputPort1Inactive;
  484. priv->data[1] |= cOutputPort2Inactive;
  485. tda9887_set_config(t,priv->data);
  486. tda9887_set_insmod(t,priv->data);
  487. if (t->mode == T_STANDBY) {
  488. priv->data[1] |= cForcedMuteAudioON;
  489. }
  490. tda9887_dbg("writing: b=0x%02x c=0x%02x e=0x%02x\n",
  491. priv->data[1],priv->data[2],priv->data[3]);
  492. if (tuner_debug > 1)
  493. dump_write_message(t, priv->data);
  494. if (4 != (rc = tuner_i2c_xfer_send(&priv->i2c_props,priv->data,4)))
  495. tda9887_info("i2c i/o error: rc == %d (should be 4)\n",rc);
  496. if (tuner_debug > 2) {
  497. msleep_interruptible(1000);
  498. tda9887_status(t);
  499. }
  500. }
  501. /* ---------------------------------------------------------------------- */
  502. static void tda9887_tuner_status(struct tuner *t)
  503. {
  504. struct tda9887_priv *priv = t->priv;
  505. tda9887_info("Data bytes: b=0x%02x c=0x%02x e=0x%02x\n", priv->data[1], priv->data[2], priv->data[3]);
  506. }
  507. static int tda9887_get_afc(struct tuner *t)
  508. {
  509. struct tda9887_priv *priv = t->priv;
  510. static int AFC_BITS_2_kHz[] = {
  511. -12500, -37500, -62500, -97500,
  512. -112500, -137500, -162500, -187500,
  513. 187500, 162500, 137500, 112500,
  514. 97500 , 62500, 37500 , 12500
  515. };
  516. int afc=0;
  517. __u8 reg = 0;
  518. if (1 == tuner_i2c_xfer_recv(&priv->i2c_props,&reg,1))
  519. afc = AFC_BITS_2_kHz[(reg>>1)&0x0f];
  520. return afc;
  521. }
  522. static void tda9887_standby(struct tuner *t)
  523. {
  524. tda9887_configure(t);
  525. }
  526. static void tda9887_set_freq(struct tuner *t, unsigned int freq)
  527. {
  528. tda9887_configure(t);
  529. }
  530. static void tda9887_release(struct tuner *t)
  531. {
  532. kfree(t->priv);
  533. t->priv = NULL;
  534. }
  535. static struct tuner_operations tda9887_tuner_ops = {
  536. .set_tv_freq = tda9887_set_freq,
  537. .set_radio_freq = tda9887_set_freq,
  538. .standby = tda9887_standby,
  539. .tuner_status = tda9887_tuner_status,
  540. .get_afc = tda9887_get_afc,
  541. .release = tda9887_release,
  542. };
  543. int tda9887_tuner_init(struct tuner *t)
  544. {
  545. struct tda9887_priv *priv = NULL;
  546. priv = kzalloc(sizeof(struct tda9887_priv), GFP_KERNEL);
  547. if (priv == NULL)
  548. return -ENOMEM;
  549. t->priv = priv;
  550. priv->i2c_props.addr = t->i2c.addr;
  551. priv->i2c_props.adap = t->i2c.adapter;
  552. strlcpy(t->i2c.name, "tda9887", sizeof(t->i2c.name));
  553. tda9887_info("tda988[5/6/7] found @ 0x%x (%s)\n", t->i2c.addr,
  554. t->i2c.driver->driver.name);
  555. memcpy(&t->ops, &tda9887_tuner_ops, sizeof(struct tuner_operations));
  556. return 0;
  557. }
  558. /*
  559. * Overrides for Emacs so that we follow Linus's tabbing style.
  560. * ---------------------------------------------------------------------------
  561. * Local variables:
  562. * c-basic-offset: 8
  563. * End:
  564. */