tuner-simple.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  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 = 0;
  16. module_param(debug, int, 0644);
  17. MODULE_PARM_DESC(debug, "enable verbose debug messages");
  18. #define PREFIX "tuner-simple "
  19. static int offset = 0;
  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_t_params if desired_type not available */
  183. if (desired_type != tun->params[j].type) {
  184. tuner_dbg("IFPCoff = %d: tuner_t_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, Offset=%d.%02d MHz, div=%0d\n",
  207. params->frequency / 16, params->frequency % 16 * 100 / 16,
  208. IFPCoff / 16, IFPCoff % 16 * 100 / 16,
  209. offset / 16, offset % 16 * 100 / 16,
  210. 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) //also valid for V4L2_STD_SECAM
  219. cb |= PHILIPS_MF_SET_STD_L;
  220. else if (params->std & V4L2_STD_SECAM_LC)
  221. cb |= PHILIPS_MF_SET_STD_LC;
  222. else /* V4L2_STD_B|V4L2_STD_GH */
  223. cb |= PHILIPS_MF_SET_STD_BG;
  224. break;
  225. case TUNER_TEMIC_4046FM5:
  226. cb &= ~0x0f;
  227. if (params->std & V4L2_STD_PAL_BG) {
  228. cb |= TEMIC_SET_PAL_BG;
  229. } else if (params->std & V4L2_STD_PAL_I) {
  230. cb |= TEMIC_SET_PAL_I;
  231. } else if (params->std & V4L2_STD_PAL_DK) {
  232. cb |= TEMIC_SET_PAL_DK;
  233. } else if (params->std & V4L2_STD_SECAM_L) {
  234. cb |= TEMIC_SET_PAL_L;
  235. }
  236. break;
  237. case TUNER_PHILIPS_FQ1216ME:
  238. cb &= ~0x0f;
  239. if (params->std & (V4L2_STD_PAL_BG|V4L2_STD_PAL_DK)) {
  240. cb |= PHILIPS_SET_PAL_BGDK;
  241. } else if (params->std & V4L2_STD_PAL_I) {
  242. cb |= PHILIPS_SET_PAL_I;
  243. } else if (params->std & V4L2_STD_SECAM_L) {
  244. cb |= PHILIPS_SET_PAL_L;
  245. }
  246. break;
  247. case TUNER_PHILIPS_ATSC:
  248. /* 0x00 -> ATSC antenna input 1 */
  249. /* 0x01 -> ATSC antenna input 2 */
  250. /* 0x02 -> NTSC antenna input 1 */
  251. /* 0x03 -> NTSC antenna input 2 */
  252. cb &= ~0x03;
  253. if (!(params->std & V4L2_STD_ATSC))
  254. cb |= 2;
  255. /* FIXME: input */
  256. break;
  257. case TUNER_MICROTUNE_4042FI5:
  258. /* Set the charge pump for fast tuning */
  259. config |= TUNER_CHARGE_PUMP;
  260. break;
  261. case TUNER_PHILIPS_TUV1236D:
  262. /* 0x40 -> ATSC antenna input 1 */
  263. /* 0x48 -> ATSC antenna input 2 */
  264. /* 0x00 -> NTSC antenna input 1 */
  265. /* 0x08 -> NTSC antenna input 2 */
  266. buffer[0] = 0x14;
  267. buffer[1] = 0x00;
  268. buffer[2] = 0x17;
  269. buffer[3] = 0x00;
  270. cb &= ~0x40;
  271. if (params->std & V4L2_STD_ATSC) {
  272. cb |= 0x40;
  273. buffer[1] = 0x04;
  274. }
  275. /* set to the correct mode (analog or digital) */
  276. tuneraddr = priv->i2c_props.addr;
  277. priv->i2c_props.addr = 0x0a;
  278. if (2 != (rc = tuner_i2c_xfer_send(&priv->i2c_props,&buffer[0],2)))
  279. tuner_warn("i2c i/o error: rc == %d (should be 2)\n",rc);
  280. if (2 != (rc = tuner_i2c_xfer_send(&priv->i2c_props,&buffer[2],2)))
  281. tuner_warn("i2c i/o error: rc == %d (should be 2)\n",rc);
  282. priv->i2c_props.addr = tuneraddr;
  283. /* FIXME: input */
  284. break;
  285. }
  286. if (t_params->cb_first_if_lower_freq && div < priv->last_div) {
  287. buffer[0] = config;
  288. buffer[1] = cb;
  289. buffer[2] = (div>>8) & 0x7f;
  290. buffer[3] = div & 0xff;
  291. } else {
  292. buffer[0] = (div>>8) & 0x7f;
  293. buffer[1] = div & 0xff;
  294. buffer[2] = config;
  295. buffer[3] = cb;
  296. }
  297. priv->last_div = div;
  298. if (t_params->has_tda9887) {
  299. int config = 0;
  300. int is_secam_l = (params->std & (V4L2_STD_SECAM_L | V4L2_STD_SECAM_LC)) &&
  301. !(params->std & ~(V4L2_STD_SECAM_L | V4L2_STD_SECAM_LC));
  302. if (params->std == V4L2_STD_SECAM_LC) {
  303. if (t_params->port1_active ^ t_params->port1_invert_for_secam_lc)
  304. config |= TDA9887_PORT1_ACTIVE;
  305. if (t_params->port2_active ^ t_params->port2_invert_for_secam_lc)
  306. config |= TDA9887_PORT2_ACTIVE;
  307. }
  308. else {
  309. if (t_params->port1_active)
  310. config |= TDA9887_PORT1_ACTIVE;
  311. if (t_params->port2_active)
  312. config |= TDA9887_PORT2_ACTIVE;
  313. }
  314. if (t_params->intercarrier_mode)
  315. config |= TDA9887_INTERCARRIER;
  316. if (is_secam_l) {
  317. if (i == 0 && t_params->default_top_secam_low)
  318. config |= TDA9887_TOP(t_params->default_top_secam_low);
  319. else if (i == 1 && t_params->default_top_secam_mid)
  320. config |= TDA9887_TOP(t_params->default_top_secam_mid);
  321. else if (t_params->default_top_secam_high)
  322. config |= TDA9887_TOP(t_params->default_top_secam_high);
  323. }
  324. else {
  325. if (i == 0 && t_params->default_top_low)
  326. config |= TDA9887_TOP(t_params->default_top_low);
  327. else if (i == 1 && t_params->default_top_mid)
  328. config |= TDA9887_TOP(t_params->default_top_mid);
  329. else if (t_params->default_top_high)
  330. config |= TDA9887_TOP(t_params->default_top_high);
  331. }
  332. if (t_params->default_pll_gating_18)
  333. config |= TDA9887_GATING_18;
  334. i2c_clients_command(priv->i2c_props.adap, TDA9887_SET_CONFIG, &config);
  335. }
  336. tuner_dbg("tv 0x%02x 0x%02x 0x%02x 0x%02x\n",
  337. buffer[0],buffer[1],buffer[2],buffer[3]);
  338. if (4 != (rc = tuner_i2c_xfer_send(&priv->i2c_props,buffer,4)))
  339. tuner_warn("i2c i/o error: rc == %d (should be 4)\n",rc);
  340. switch (priv->type) {
  341. case TUNER_LG_TDVS_H06XF:
  342. /* Set the Auxiliary Byte. */
  343. buffer[0] = buffer[2];
  344. buffer[0] &= ~0x20;
  345. buffer[0] |= 0x18;
  346. buffer[1] = 0x20;
  347. tuner_dbg("tv 0x%02x 0x%02x\n",buffer[0],buffer[1]);
  348. if (2 != (rc = tuner_i2c_xfer_send(&priv->i2c_props,buffer,2)))
  349. tuner_warn("i2c i/o error: rc == %d (should be 2)\n",rc);
  350. break;
  351. case TUNER_MICROTUNE_4042FI5:
  352. {
  353. // FIXME - this may also work for other tuners
  354. unsigned long timeout = jiffies + msecs_to_jiffies(1);
  355. u8 status_byte = 0;
  356. /* Wait until the PLL locks */
  357. for (;;) {
  358. if (time_after(jiffies,timeout))
  359. return 0;
  360. if (1 != (rc = tuner_i2c_xfer_recv(&priv->i2c_props,&status_byte,1))) {
  361. tuner_warn("i2c i/o read error: rc == %d (should be 1)\n",rc);
  362. break;
  363. }
  364. if (status_byte & TUNER_PLL_LOCKED)
  365. break;
  366. udelay(10);
  367. }
  368. /* Set the charge pump for optimized phase noise figure */
  369. config &= ~TUNER_CHARGE_PUMP;
  370. buffer[0] = (div>>8) & 0x7f;
  371. buffer[1] = div & 0xff;
  372. buffer[2] = config;
  373. buffer[3] = cb;
  374. tuner_dbg("tv 0x%02x 0x%02x 0x%02x 0x%02x\n",
  375. buffer[0],buffer[1],buffer[2],buffer[3]);
  376. if (4 != (rc = tuner_i2c_xfer_send(&priv->i2c_props,buffer,4)))
  377. tuner_warn("i2c i/o error: rc == %d (should be 4)\n",rc);
  378. break;
  379. }
  380. }
  381. return 0;
  382. }
  383. static int simple_set_radio_freq(struct dvb_frontend *fe,
  384. struct analog_parameters *params)
  385. {
  386. struct tunertype *tun;
  387. struct tuner_simple_priv *priv = fe->tuner_priv;
  388. u8 buffer[4];
  389. u16 div;
  390. int rc, j;
  391. struct tuner_params *t_params;
  392. unsigned int freq = params->frequency;
  393. tun = priv->tun;
  394. for (j = tun->count-1; j > 0; j--)
  395. if (tun->params[j].type == TUNER_PARAM_TYPE_RADIO)
  396. break;
  397. /* default t_params (j=0) will be used if desired type wasn't found */
  398. t_params = &tun->params[j];
  399. /* Select Radio 1st IF used */
  400. switch (t_params->radio_if) {
  401. case 0: /* 10.7 MHz */
  402. freq += (unsigned int)(10.7*16000);
  403. break;
  404. case 1: /* 33.3 MHz */
  405. freq += (unsigned int)(33.3*16000);
  406. break;
  407. case 2: /* 41.3 MHz */
  408. freq += (unsigned int)(41.3*16000);
  409. break;
  410. default:
  411. tuner_warn("Unsupported radio_if value %d\n", t_params->radio_if);
  412. return 0;
  413. }
  414. /* Bandswitch byte */
  415. switch (priv->type) {
  416. case TUNER_TENA_9533_DI:
  417. case TUNER_YMEC_TVF_5533MF:
  418. tuner_dbg("This tuner doesn't have FM. Most cards have a TEA5767 for FM\n");
  419. return 0;
  420. case TUNER_PHILIPS_FM1216ME_MK3:
  421. case TUNER_PHILIPS_FM1236_MK3:
  422. case TUNER_PHILIPS_FMD1216ME_MK3:
  423. case TUNER_LG_NTSC_TAPE:
  424. case TUNER_PHILIPS_FM1256_IH3:
  425. buffer[3] = 0x19;
  426. break;
  427. case TUNER_TNF_5335MF:
  428. buffer[3] = 0x11;
  429. break;
  430. case TUNER_LG_PAL_FM:
  431. buffer[3] = 0xa5;
  432. break;
  433. case TUNER_THOMSON_DTT761X:
  434. buffer[3] = 0x39;
  435. break;
  436. case TUNER_MICROTUNE_4049FM5:
  437. default:
  438. buffer[3] = 0xa4;
  439. break;
  440. }
  441. buffer[2] = (t_params->ranges[0].config & ~TUNER_RATIO_MASK) |
  442. TUNER_RATIO_SELECT_50; /* 50 kHz step */
  443. /* Convert from 1/16 kHz V4L steps to 1/20 MHz (=50 kHz) PLL steps
  444. freq * (1 Mhz / 16000 V4L steps) * (20 PLL steps / 1 MHz) =
  445. freq * (1/800) */
  446. div = (freq + 400) / 800;
  447. if (t_params->cb_first_if_lower_freq && div < priv->last_div) {
  448. buffer[0] = buffer[2];
  449. buffer[1] = buffer[3];
  450. buffer[2] = (div>>8) & 0x7f;
  451. buffer[3] = div & 0xff;
  452. } else {
  453. buffer[0] = (div>>8) & 0x7f;
  454. buffer[1] = div & 0xff;
  455. }
  456. tuner_dbg("radio 0x%02x 0x%02x 0x%02x 0x%02x\n",
  457. buffer[0],buffer[1],buffer[2],buffer[3]);
  458. priv->last_div = div;
  459. if (t_params->has_tda9887) {
  460. int config = 0;
  461. if (t_params->port1_active && !t_params->port1_fm_high_sensitivity)
  462. config |= TDA9887_PORT1_ACTIVE;
  463. if (t_params->port2_active && !t_params->port2_fm_high_sensitivity)
  464. config |= TDA9887_PORT2_ACTIVE;
  465. if (t_params->intercarrier_mode)
  466. config |= TDA9887_INTERCARRIER;
  467. /* if (t_params->port1_set_for_fm_mono)
  468. config &= ~TDA9887_PORT1_ACTIVE;*/
  469. if (t_params->fm_gain_normal)
  470. config |= TDA9887_GAIN_NORMAL;
  471. if (t_params->radio_if == 2)
  472. config |= TDA9887_RIF_41_3;
  473. i2c_clients_command(priv->i2c_props.adap, TDA9887_SET_CONFIG, &config);
  474. }
  475. if (4 != (rc = tuner_i2c_xfer_send(&priv->i2c_props,buffer,4)))
  476. tuner_warn("i2c i/o error: rc == %d (should be 4)\n",rc);
  477. return 0;
  478. }
  479. static int simple_set_params(struct dvb_frontend *fe,
  480. struct analog_parameters *params)
  481. {
  482. struct tuner_simple_priv *priv = fe->tuner_priv;
  483. int ret = -EINVAL;
  484. switch (params->mode) {
  485. case V4L2_TUNER_RADIO:
  486. ret = simple_set_radio_freq(fe, params);
  487. priv->frequency = params->frequency * 125 / 2;
  488. break;
  489. case V4L2_TUNER_ANALOG_TV:
  490. case V4L2_TUNER_DIGITAL_TV:
  491. ret = simple_set_tv_freq(fe, params);
  492. priv->frequency = params->frequency * 62500;
  493. break;
  494. }
  495. return ret;
  496. }
  497. static int simple_release(struct dvb_frontend *fe)
  498. {
  499. kfree(fe->tuner_priv);
  500. fe->tuner_priv = NULL;
  501. return 0;
  502. }
  503. static int simple_get_frequency(struct dvb_frontend *fe, u32 *frequency)
  504. {
  505. struct tuner_simple_priv *priv = fe->tuner_priv;
  506. *frequency = priv->frequency;
  507. return 0;
  508. }
  509. static struct dvb_tuner_ops simple_tuner_ops = {
  510. .set_analog_params = simple_set_params,
  511. .release = simple_release,
  512. .get_frequency = simple_get_frequency,
  513. .get_status = simple_get_status,
  514. .get_rf_strength = simple_get_rf_strength,
  515. };
  516. struct dvb_frontend *simple_tuner_attach(struct dvb_frontend *fe,
  517. struct i2c_adapter *i2c_adap,
  518. u8 i2c_addr,
  519. struct simple_tuner_config *cfg)
  520. {
  521. struct tuner_simple_priv *priv = NULL;
  522. priv = kzalloc(sizeof(struct tuner_simple_priv), GFP_KERNEL);
  523. if (priv == NULL)
  524. return NULL;
  525. fe->tuner_priv = priv;
  526. priv->i2c_props.addr = i2c_addr;
  527. priv->i2c_props.adap = i2c_adap;
  528. priv->type = cfg->type;
  529. priv->tun = cfg->tun;
  530. memcpy(&fe->ops.tuner_ops, &simple_tuner_ops, sizeof(struct dvb_tuner_ops));
  531. tuner_info("type set to %d (%s)\n", cfg->type, cfg->tun->name);
  532. strlcpy(fe->ops.tuner_ops.info.name, cfg->tun->name, sizeof(fe->ops.tuner_ops.info.name));
  533. return fe;
  534. }
  535. EXPORT_SYMBOL_GPL(simple_tuner_attach);
  536. MODULE_DESCRIPTION("Simple 4-control-bytes style tuner driver");
  537. MODULE_AUTHOR("Ralph Metzler, Gerd Knorr, Gunther Mayer");
  538. MODULE_LICENSE("GPL");
  539. /*
  540. * Overrides for Emacs so that we follow Linus's tabbing style.
  541. * ---------------------------------------------------------------------------
  542. * Local variables:
  543. * c-basic-offset: 8
  544. * End:
  545. */