tuner-simple.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670
  1. /*
  2. * i2c tv tuner chip device driver
  3. * controls all those simple 4-control-bytes style tuners.
  4. *
  5. * This "tuner-simple" module was split apart from the original "tuner" module.
  6. */
  7. #include <linux/delay.h>
  8. #include <linux/i2c.h>
  9. #include <linux/videodev.h>
  10. #include <media/tuner.h>
  11. #include <media/v4l2-common.h>
  12. #include <media/tuner-types.h>
  13. #include "tuner-i2c.h"
  14. #include "tuner-simple.h"
  15. static int debug;
  16. module_param(debug, int, 0644);
  17. MODULE_PARM_DESC(debug, "enable verbose debug messages");
  18. #define PREFIX "tuner-simple"
  19. static int offset;
  20. module_param(offset, int, 0664);
  21. MODULE_PARM_DESC(offset, "Allows to specify an offset for tuner");
  22. /* ---------------------------------------------------------------------- */
  23. /* tv standard selection for Temic 4046 FM5
  24. this value takes the low bits of control byte 2
  25. from datasheet Rev.01, Feb.00
  26. standard BG I L L2 D
  27. picture IF 38.9 38.9 38.9 33.95 38.9
  28. sound 1 33.4 32.9 32.4 40.45 32.4
  29. sound 2 33.16
  30. NICAM 33.05 32.348 33.05 33.05
  31. */
  32. #define TEMIC_SET_PAL_I 0x05
  33. #define TEMIC_SET_PAL_DK 0x09
  34. #define TEMIC_SET_PAL_L 0x0a /* SECAM ? */
  35. #define TEMIC_SET_PAL_L2 0x0b /* change IF ! */
  36. #define TEMIC_SET_PAL_BG 0x0c
  37. /* tv tuner system standard selection for Philips FQ1216ME
  38. this value takes the low bits of control byte 2
  39. from datasheet "1999 Nov 16" (supersedes "1999 Mar 23")
  40. standard BG DK I L L`
  41. picture carrier 38.90 38.90 38.90 38.90 33.95
  42. colour 34.47 34.47 34.47 34.47 38.38
  43. sound 1 33.40 32.40 32.90 32.40 40.45
  44. sound 2 33.16 - - - -
  45. NICAM 33.05 33.05 32.35 33.05 39.80
  46. */
  47. #define PHILIPS_SET_PAL_I 0x01 /* Bit 2 always zero !*/
  48. #define PHILIPS_SET_PAL_BGDK 0x09
  49. #define PHILIPS_SET_PAL_L2 0x0a
  50. #define PHILIPS_SET_PAL_L 0x0b
  51. /* system switching for Philips FI1216MF MK2
  52. from datasheet "1996 Jul 09",
  53. standard BG L L'
  54. picture carrier 38.90 38.90 33.95
  55. colour 34.47 34.37 38.38
  56. sound 1 33.40 32.40 40.45
  57. sound 2 33.16 - -
  58. NICAM 33.05 33.05 39.80
  59. */
  60. #define PHILIPS_MF_SET_STD_BG 0x01 /* Bit 2 must be zero, Bit 3 is system output */
  61. #define PHILIPS_MF_SET_STD_L 0x03 /* Used on Secam France */
  62. #define PHILIPS_MF_SET_STD_LC 0x02 /* Used on SECAM L' */
  63. /* Control byte */
  64. #define TUNER_RATIO_MASK 0x06 /* Bit cb1:cb2 */
  65. #define TUNER_RATIO_SELECT_50 0x00
  66. #define TUNER_RATIO_SELECT_32 0x02
  67. #define TUNER_RATIO_SELECT_166 0x04
  68. #define TUNER_RATIO_SELECT_62 0x06
  69. #define TUNER_CHARGE_PUMP 0x40 /* Bit cb6 */
  70. /* Status byte */
  71. #define TUNER_POR 0x80
  72. #define TUNER_FL 0x40
  73. #define TUNER_MODE 0x38
  74. #define TUNER_AFC 0x07
  75. #define TUNER_SIGNAL 0x07
  76. #define TUNER_STEREO 0x10
  77. #define TUNER_PLL_LOCKED 0x40
  78. #define TUNER_STEREO_MK3 0x04
  79. struct tuner_simple_priv {
  80. u16 last_div;
  81. struct tuner_i2c_props i2c_props;
  82. unsigned int type;
  83. struct tunertype *tun;
  84. u32 frequency;
  85. };
  86. /* ---------------------------------------------------------------------- */
  87. static int tuner_read_status(struct dvb_frontend *fe)
  88. {
  89. struct tuner_simple_priv *priv = fe->tuner_priv;
  90. unsigned char byte;
  91. if (1 != tuner_i2c_xfer_recv(&priv->i2c_props, &byte, 1))
  92. return 0;
  93. return byte;
  94. }
  95. static inline int tuner_signal(const int status)
  96. {
  97. return (status & TUNER_SIGNAL) << 13;
  98. }
  99. static inline int tuner_stereo(const int type, const int status)
  100. {
  101. switch (type) {
  102. case TUNER_PHILIPS_FM1216ME_MK3:
  103. case TUNER_PHILIPS_FM1236_MK3:
  104. case TUNER_PHILIPS_FM1256_IH3:
  105. case TUNER_LG_NTSC_TAPE:
  106. return ((status & TUNER_SIGNAL) == TUNER_STEREO_MK3);
  107. default:
  108. return status & TUNER_STEREO;
  109. }
  110. }
  111. static inline int tuner_islocked(const int status)
  112. {
  113. return (status & TUNER_FL);
  114. }
  115. static inline int tuner_afcstatus(const int status)
  116. {
  117. return (status & TUNER_AFC) - 2;
  118. }
  119. static int simple_get_status(struct dvb_frontend *fe, u32 *status)
  120. {
  121. struct tuner_simple_priv *priv = fe->tuner_priv;
  122. int tuner_status = tuner_read_status(fe);
  123. *status = 0;
  124. if (tuner_islocked(tuner_status))
  125. *status = TUNER_STATUS_LOCKED;
  126. if (tuner_stereo(priv->type, tuner_status))
  127. *status |= TUNER_STATUS_STEREO;
  128. tuner_dbg("AFC Status: %d\n", tuner_afcstatus(tuner_status));
  129. return 0;
  130. }
  131. static int simple_get_rf_strength(struct dvb_frontend *fe, u16 *strength)
  132. {
  133. struct tuner_simple_priv *priv = fe->tuner_priv;
  134. int signal = tuner_signal(tuner_read_status(fe));
  135. *strength = signal;
  136. tuner_dbg("Signal strength: %d\n", signal);
  137. return 0;
  138. }
  139. /* ---------------------------------------------------------------------- */
  140. static int simple_set_tv_freq(struct dvb_frontend *fe,
  141. struct analog_parameters *params)
  142. {
  143. struct tuner_simple_priv *priv = fe->tuner_priv;
  144. u8 config, cb, tuneraddr;
  145. u16 div;
  146. struct tunertype *tun;
  147. u8 buffer[4];
  148. int rc, IFPCoff, i, j;
  149. enum param_type desired_type;
  150. struct tuner_params *t_params;
  151. tun = priv->tun;
  152. /* IFPCoff = Video Intermediate Frequency - Vif:
  153. 940 =16*58.75 NTSC/J (Japan)
  154. 732 =16*45.75 M/N STD
  155. 704 =16*44 ATSC (at DVB code)
  156. 632 =16*39.50 I U.K.
  157. 622.4=16*38.90 B/G D/K I, L STD
  158. 592 =16*37.00 D China
  159. 590 =16.36.875 B Australia
  160. 543.2=16*33.95 L' STD
  161. 171.2=16*10.70 FM Radio (at set_radio_freq)
  162. */
  163. if (params->std == V4L2_STD_NTSC_M_JP) {
  164. IFPCoff = 940;
  165. desired_type = TUNER_PARAM_TYPE_NTSC;
  166. } else if ((params->std & V4L2_STD_MN) &&
  167. !(params->std & ~V4L2_STD_MN)) {
  168. IFPCoff = 732;
  169. desired_type = TUNER_PARAM_TYPE_NTSC;
  170. } else if (params->std == V4L2_STD_SECAM_LC) {
  171. IFPCoff = 543;
  172. desired_type = TUNER_PARAM_TYPE_SECAM;
  173. } else {
  174. IFPCoff = 623;
  175. desired_type = TUNER_PARAM_TYPE_PAL;
  176. }
  177. for (j = 0; j < tun->count-1; j++) {
  178. if (desired_type != tun->params[j].type)
  179. continue;
  180. break;
  181. }
  182. /* use default tuner params if desired_type not available */
  183. if (desired_type != tun->params[j].type) {
  184. tuner_dbg("IFPCoff = %d: params undefined for tuner %d\n",
  185. IFPCoff, priv->type);
  186. j = 0;
  187. }
  188. t_params = &tun->params[j];
  189. for (i = 0; i < t_params->count; i++) {
  190. if (params->frequency > t_params->ranges[i].limit)
  191. continue;
  192. break;
  193. }
  194. if (i == t_params->count) {
  195. tuner_dbg("TV frequency out of range (%d > %d)",
  196. params->frequency, t_params->ranges[i - 1].limit);
  197. params->frequency = t_params->ranges[--i].limit;
  198. }
  199. config = t_params->ranges[i].config;
  200. cb = t_params->ranges[i].cb;
  201. /* i == 0 -> VHF_LO
  202. * i == 1 -> VHF_HI
  203. * i == 2 -> UHF */
  204. tuner_dbg("tv: param %d, range %d\n", j, i);
  205. div = params->frequency + IFPCoff + offset;
  206. tuner_dbg("Freq= %d.%02d MHz, V_IF=%d.%02d MHz, "
  207. "Offset=%d.%02d MHz, div=%0d\n",
  208. params->frequency / 16, params->frequency % 16 * 100 / 16,
  209. IFPCoff / 16, IFPCoff % 16 * 100 / 16,
  210. offset / 16, offset % 16 * 100 / 16, div);
  211. /* tv norm specific stuff for multi-norm tuners */
  212. switch (priv->type) {
  213. case TUNER_PHILIPS_SECAM: /* FI1216MF */
  214. /* 0x01 -> ??? no change ??? */
  215. /* 0x02 -> PAL BDGHI / SECAM L */
  216. /* 0x04 -> ??? PAL others / SECAM others ??? */
  217. cb &= ~0x03;
  218. if (params->std & V4L2_STD_SECAM_L)
  219. /* also valid for V4L2_STD_SECAM */
  220. cb |= PHILIPS_MF_SET_STD_L;
  221. else if (params->std & V4L2_STD_SECAM_LC)
  222. cb |= PHILIPS_MF_SET_STD_LC;
  223. else /* V4L2_STD_B|V4L2_STD_GH */
  224. cb |= PHILIPS_MF_SET_STD_BG;
  225. break;
  226. case TUNER_TEMIC_4046FM5:
  227. cb &= ~0x0f;
  228. if (params->std & V4L2_STD_PAL_BG) {
  229. cb |= TEMIC_SET_PAL_BG;
  230. } else if (params->std & V4L2_STD_PAL_I) {
  231. cb |= TEMIC_SET_PAL_I;
  232. } else if (params->std & V4L2_STD_PAL_DK) {
  233. cb |= TEMIC_SET_PAL_DK;
  234. } else if (params->std & V4L2_STD_SECAM_L) {
  235. cb |= TEMIC_SET_PAL_L;
  236. }
  237. break;
  238. case TUNER_PHILIPS_FQ1216ME:
  239. cb &= ~0x0f;
  240. if (params->std & (V4L2_STD_PAL_BG|V4L2_STD_PAL_DK)) {
  241. cb |= PHILIPS_SET_PAL_BGDK;
  242. } else if (params->std & V4L2_STD_PAL_I) {
  243. cb |= PHILIPS_SET_PAL_I;
  244. } else if (params->std & V4L2_STD_SECAM_L) {
  245. cb |= PHILIPS_SET_PAL_L;
  246. }
  247. break;
  248. case TUNER_PHILIPS_ATSC:
  249. /* 0x00 -> ATSC antenna input 1 */
  250. /* 0x01 -> ATSC antenna input 2 */
  251. /* 0x02 -> NTSC antenna input 1 */
  252. /* 0x03 -> NTSC antenna input 2 */
  253. cb &= ~0x03;
  254. if (!(params->std & V4L2_STD_ATSC))
  255. cb |= 2;
  256. /* FIXME: input */
  257. break;
  258. case TUNER_MICROTUNE_4042FI5:
  259. /* Set the charge pump for fast tuning */
  260. config |= TUNER_CHARGE_PUMP;
  261. break;
  262. case TUNER_PHILIPS_TUV1236D:
  263. /* 0x40 -> ATSC antenna input 1 */
  264. /* 0x48 -> ATSC antenna input 2 */
  265. /* 0x00 -> NTSC antenna input 1 */
  266. /* 0x08 -> NTSC antenna input 2 */
  267. buffer[0] = 0x14;
  268. buffer[1] = 0x00;
  269. buffer[2] = 0x17;
  270. buffer[3] = 0x00;
  271. cb &= ~0x40;
  272. if (params->std & V4L2_STD_ATSC) {
  273. cb |= 0x40;
  274. buffer[1] = 0x04;
  275. }
  276. /* set to the correct mode (analog or digital) */
  277. tuneraddr = priv->i2c_props.addr;
  278. priv->i2c_props.addr = 0x0a;
  279. rc = tuner_i2c_xfer_send(&priv->i2c_props, &buffer[0], 2);
  280. if (2 != rc)
  281. tuner_warn("i2c i/o error: rc == %d "
  282. "(should be 2)\n", rc);
  283. rc = tuner_i2c_xfer_send(&priv->i2c_props, &buffer[2], 2);
  284. if (2 != rc)
  285. tuner_warn("i2c i/o error: rc == %d "
  286. "(should be 2)\n", rc);
  287. priv->i2c_props.addr = tuneraddr;
  288. /* FIXME: input */
  289. break;
  290. }
  291. if (t_params->cb_first_if_lower_freq && div < priv->last_div) {
  292. buffer[0] = config;
  293. buffer[1] = cb;
  294. buffer[2] = (div>>8) & 0x7f;
  295. buffer[3] = div & 0xff;
  296. } else {
  297. buffer[0] = (div>>8) & 0x7f;
  298. buffer[1] = div & 0xff;
  299. buffer[2] = config;
  300. buffer[3] = cb;
  301. }
  302. priv->last_div = div;
  303. if (t_params->has_tda9887) {
  304. struct v4l2_priv_tun_config tda9887_cfg;
  305. int config = 0;
  306. int is_secam_l = (params->std & (V4L2_STD_SECAM_L |
  307. V4L2_STD_SECAM_LC)) &&
  308. !(params->std & ~(V4L2_STD_SECAM_L |
  309. V4L2_STD_SECAM_LC));
  310. tda9887_cfg.tuner = TUNER_TDA9887;
  311. tda9887_cfg.priv = &config;
  312. if (params->std == V4L2_STD_SECAM_LC) {
  313. if (t_params->port1_active ^ t_params->port1_invert_for_secam_lc)
  314. config |= TDA9887_PORT1_ACTIVE;
  315. if (t_params->port2_active ^ t_params->port2_invert_for_secam_lc)
  316. config |= TDA9887_PORT2_ACTIVE;
  317. } else {
  318. if (t_params->port1_active)
  319. config |= TDA9887_PORT1_ACTIVE;
  320. if (t_params->port2_active)
  321. config |= TDA9887_PORT2_ACTIVE;
  322. }
  323. if (t_params->intercarrier_mode)
  324. config |= TDA9887_INTERCARRIER;
  325. if (is_secam_l) {
  326. if (i == 0 && t_params->default_top_secam_low)
  327. config |= TDA9887_TOP(t_params->default_top_secam_low);
  328. else if (i == 1 && t_params->default_top_secam_mid)
  329. config |= TDA9887_TOP(t_params->default_top_secam_mid);
  330. else if (t_params->default_top_secam_high)
  331. config |= TDA9887_TOP(t_params->default_top_secam_high);
  332. } else {
  333. if (i == 0 && t_params->default_top_low)
  334. config |= TDA9887_TOP(t_params->default_top_low);
  335. else if (i == 1 && t_params->default_top_mid)
  336. config |= TDA9887_TOP(t_params->default_top_mid);
  337. else if (t_params->default_top_high)
  338. config |= TDA9887_TOP(t_params->default_top_high);
  339. }
  340. if (t_params->default_pll_gating_18)
  341. config |= TDA9887_GATING_18;
  342. i2c_clients_command(priv->i2c_props.adap, TUNER_SET_CONFIG,
  343. &tda9887_cfg);
  344. }
  345. tuner_dbg("tv 0x%02x 0x%02x 0x%02x 0x%02x\n",
  346. buffer[0], buffer[1], buffer[2], buffer[3]);
  347. rc = tuner_i2c_xfer_send(&priv->i2c_props, buffer, 4);
  348. if (4 != rc)
  349. tuner_warn("i2c i/o error: rc == %d (should be 4)\n", rc);
  350. switch (priv->type) {
  351. case TUNER_LG_TDVS_H06XF:
  352. /* Set the Auxiliary Byte. */
  353. buffer[0] = buffer[2];
  354. buffer[0] &= ~0x20;
  355. buffer[0] |= 0x18;
  356. buffer[1] = 0x20;
  357. tuner_dbg("tv 0x%02x 0x%02x\n", buffer[0], buffer[1]);
  358. rc = tuner_i2c_xfer_send(&priv->i2c_props, buffer, 2);
  359. if (2 != rc)
  360. tuner_warn("i2c i/o error: rc == %d "
  361. "(should be 2)\n", rc);
  362. break;
  363. case TUNER_MICROTUNE_4042FI5:
  364. {
  365. /* FIXME - this may also work for other tuners */
  366. unsigned long timeout = jiffies + msecs_to_jiffies(1);
  367. u8 status_byte = 0;
  368. /* Wait until the PLL locks */
  369. for (;;) {
  370. if (time_after(jiffies, timeout))
  371. return 0;
  372. rc = tuner_i2c_xfer_recv(&priv->i2c_props,
  373. &status_byte, 1);
  374. if (1 != rc) {
  375. tuner_warn("i2c i/o read error: rc == %d "
  376. "(should be 1)\n", rc);
  377. break;
  378. }
  379. if (status_byte & TUNER_PLL_LOCKED)
  380. break;
  381. udelay(10);
  382. }
  383. /* Set the charge pump for optimized phase noise figure */
  384. config &= ~TUNER_CHARGE_PUMP;
  385. buffer[0] = (div>>8) & 0x7f;
  386. buffer[1] = div & 0xff;
  387. buffer[2] = config;
  388. buffer[3] = cb;
  389. tuner_dbg("tv 0x%02x 0x%02x 0x%02x 0x%02x\n",
  390. buffer[0], buffer[1], buffer[2], buffer[3]);
  391. rc = tuner_i2c_xfer_send(&priv->i2c_props, buffer, 4);
  392. if (4 != rc)
  393. tuner_warn("i2c i/o error: rc == %d "
  394. "(should be 4)\n", rc);
  395. break;
  396. }
  397. }
  398. return 0;
  399. }
  400. static int simple_set_radio_freq(struct dvb_frontend *fe,
  401. struct analog_parameters *params)
  402. {
  403. struct tunertype *tun;
  404. struct tuner_simple_priv *priv = fe->tuner_priv;
  405. u8 buffer[4];
  406. u16 div;
  407. int rc, j;
  408. struct tuner_params *t_params;
  409. unsigned int freq = params->frequency;
  410. tun = priv->tun;
  411. for (j = tun->count-1; j > 0; j--)
  412. if (tun->params[j].type == TUNER_PARAM_TYPE_RADIO)
  413. break;
  414. /* default t_params (j=0) will be used if desired type wasn't found */
  415. t_params = &tun->params[j];
  416. /* Select Radio 1st IF used */
  417. switch (t_params->radio_if) {
  418. case 0: /* 10.7 MHz */
  419. freq += (unsigned int)(10.7*16000);
  420. break;
  421. case 1: /* 33.3 MHz */
  422. freq += (unsigned int)(33.3*16000);
  423. break;
  424. case 2: /* 41.3 MHz */
  425. freq += (unsigned int)(41.3*16000);
  426. break;
  427. default:
  428. tuner_warn("Unsupported radio_if value %d\n",
  429. t_params->radio_if);
  430. return 0;
  431. }
  432. /* Bandswitch byte */
  433. switch (priv->type) {
  434. case TUNER_TENA_9533_DI:
  435. case TUNER_YMEC_TVF_5533MF:
  436. tuner_dbg("This tuner doesn't have FM. "
  437. "Most cards have a TEA5767 for FM\n");
  438. return 0;
  439. case TUNER_PHILIPS_FM1216ME_MK3:
  440. case TUNER_PHILIPS_FM1236_MK3:
  441. case TUNER_PHILIPS_FMD1216ME_MK3:
  442. case TUNER_LG_NTSC_TAPE:
  443. case TUNER_PHILIPS_FM1256_IH3:
  444. buffer[3] = 0x19;
  445. break;
  446. case TUNER_TNF_5335MF:
  447. buffer[3] = 0x11;
  448. break;
  449. case TUNER_LG_PAL_FM:
  450. buffer[3] = 0xa5;
  451. break;
  452. case TUNER_THOMSON_DTT761X:
  453. buffer[3] = 0x39;
  454. break;
  455. case TUNER_MICROTUNE_4049FM5:
  456. default:
  457. buffer[3] = 0xa4;
  458. break;
  459. }
  460. buffer[2] = (t_params->ranges[0].config & ~TUNER_RATIO_MASK) |
  461. TUNER_RATIO_SELECT_50; /* 50 kHz step */
  462. /* Convert from 1/16 kHz V4L steps to 1/20 MHz (=50 kHz) PLL steps
  463. freq * (1 Mhz / 16000 V4L steps) * (20 PLL steps / 1 MHz) =
  464. freq * (1/800) */
  465. div = (freq + 400) / 800;
  466. if (t_params->cb_first_if_lower_freq && div < priv->last_div) {
  467. buffer[0] = buffer[2];
  468. buffer[1] = buffer[3];
  469. buffer[2] = (div>>8) & 0x7f;
  470. buffer[3] = div & 0xff;
  471. } else {
  472. buffer[0] = (div>>8) & 0x7f;
  473. buffer[1] = div & 0xff;
  474. }
  475. tuner_dbg("radio 0x%02x 0x%02x 0x%02x 0x%02x\n",
  476. buffer[0], buffer[1], buffer[2], buffer[3]);
  477. priv->last_div = div;
  478. if (t_params->has_tda9887) {
  479. int config = 0;
  480. struct v4l2_priv_tun_config tda9887_cfg;
  481. tda9887_cfg.tuner = TUNER_TDA9887;
  482. tda9887_cfg.priv = &config;
  483. if (t_params->port1_active &&
  484. !t_params->port1_fm_high_sensitivity)
  485. config |= TDA9887_PORT1_ACTIVE;
  486. if (t_params->port2_active &&
  487. !t_params->port2_fm_high_sensitivity)
  488. config |= TDA9887_PORT2_ACTIVE;
  489. if (t_params->intercarrier_mode)
  490. config |= TDA9887_INTERCARRIER;
  491. /* if (t_params->port1_set_for_fm_mono)
  492. config &= ~TDA9887_PORT1_ACTIVE;*/
  493. if (t_params->fm_gain_normal)
  494. config |= TDA9887_GAIN_NORMAL;
  495. if (t_params->radio_if == 2)
  496. config |= TDA9887_RIF_41_3;
  497. i2c_clients_command(priv->i2c_props.adap, TUNER_SET_CONFIG,
  498. &tda9887_cfg);
  499. }
  500. rc = tuner_i2c_xfer_send(&priv->i2c_props, buffer, 4);
  501. if (4 != rc)
  502. tuner_warn("i2c i/o error: rc == %d (should be 4)\n", rc);
  503. return 0;
  504. }
  505. static int simple_set_params(struct dvb_frontend *fe,
  506. struct analog_parameters *params)
  507. {
  508. struct tuner_simple_priv *priv = fe->tuner_priv;
  509. int ret = -EINVAL;
  510. switch (params->mode) {
  511. case V4L2_TUNER_RADIO:
  512. ret = simple_set_radio_freq(fe, params);
  513. priv->frequency = params->frequency * 125 / 2;
  514. break;
  515. case V4L2_TUNER_ANALOG_TV:
  516. case V4L2_TUNER_DIGITAL_TV:
  517. ret = simple_set_tv_freq(fe, params);
  518. priv->frequency = params->frequency * 62500;
  519. break;
  520. }
  521. return ret;
  522. }
  523. static int simple_release(struct dvb_frontend *fe)
  524. {
  525. kfree(fe->tuner_priv);
  526. fe->tuner_priv = NULL;
  527. return 0;
  528. }
  529. static int simple_get_frequency(struct dvb_frontend *fe, u32 *frequency)
  530. {
  531. struct tuner_simple_priv *priv = fe->tuner_priv;
  532. *frequency = priv->frequency;
  533. return 0;
  534. }
  535. static struct dvb_tuner_ops simple_tuner_ops = {
  536. .set_analog_params = simple_set_params,
  537. .release = simple_release,
  538. .get_frequency = simple_get_frequency,
  539. .get_status = simple_get_status,
  540. .get_rf_strength = simple_get_rf_strength,
  541. };
  542. struct dvb_frontend *simple_tuner_attach(struct dvb_frontend *fe,
  543. struct i2c_adapter *i2c_adap,
  544. u8 i2c_addr,
  545. struct simple_tuner_config *cfg)
  546. {
  547. struct tuner_simple_priv *priv = NULL;
  548. priv = kzalloc(sizeof(struct tuner_simple_priv), GFP_KERNEL);
  549. if (priv == NULL)
  550. return NULL;
  551. fe->tuner_priv = priv;
  552. priv->i2c_props.addr = i2c_addr;
  553. priv->i2c_props.adap = i2c_adap;
  554. priv->type = cfg->type;
  555. priv->tun = cfg->tun;
  556. memcpy(&fe->ops.tuner_ops, &simple_tuner_ops,
  557. sizeof(struct dvb_tuner_ops));
  558. tuner_info("type set to %d (%s)\n", cfg->type, cfg->tun->name);
  559. strlcpy(fe->ops.tuner_ops.info.name, cfg->tun->name,
  560. sizeof(fe->ops.tuner_ops.info.name));
  561. return fe;
  562. }
  563. EXPORT_SYMBOL_GPL(simple_tuner_attach);
  564. MODULE_DESCRIPTION("Simple 4-control-bytes style tuner driver");
  565. MODULE_AUTHOR("Ralph Metzler, Gerd Knorr, Gunther Mayer");
  566. MODULE_LICENSE("GPL");
  567. /*
  568. * Overrides for Emacs so that we follow Linus's tabbing style.
  569. * ---------------------------------------------------------------------------
  570. * Local variables:
  571. * c-basic-offset: 8
  572. * End:
  573. */