tuner-simple.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627
  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_getstatus(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 int tuner_signal(struct dvb_frontend *fe)
  96. {
  97. return (tuner_getstatus(fe) & TUNER_SIGNAL) << 13;
  98. }
  99. static int tuner_stereo(struct dvb_frontend *fe)
  100. {
  101. struct tuner_simple_priv *priv = fe->tuner_priv;
  102. int stereo, status;
  103. status = tuner_getstatus(fe);
  104. switch (priv->type) {
  105. case TUNER_PHILIPS_FM1216ME_MK3:
  106. case TUNER_PHILIPS_FM1236_MK3:
  107. case TUNER_PHILIPS_FM1256_IH3:
  108. case TUNER_LG_NTSC_TAPE:
  109. stereo = ((status & TUNER_SIGNAL) == TUNER_STEREO_MK3);
  110. break;
  111. default:
  112. stereo = status & TUNER_STEREO;
  113. }
  114. return stereo;
  115. }
  116. static int simple_get_status(struct dvb_frontend *fe, u32 *status)
  117. {
  118. struct tuner_simple_priv *priv = fe->tuner_priv;
  119. int signal = tuner_signal(fe);
  120. *status = 0;
  121. if (signal)
  122. *status = TUNER_STATUS_LOCKED;
  123. if (tuner_stereo(fe))
  124. *status |= TUNER_STATUS_STEREO;
  125. tuner_dbg("tuner-simple: Signal strength: %d\n", signal);
  126. return 0;
  127. }
  128. /* ---------------------------------------------------------------------- */
  129. static int simple_set_tv_freq(struct dvb_frontend *fe,
  130. struct analog_parameters *params)
  131. {
  132. struct tuner_simple_priv *priv = fe->tuner_priv;
  133. u8 config, cb, tuneraddr;
  134. u16 div;
  135. struct tunertype *tun;
  136. u8 buffer[4];
  137. int rc, IFPCoff, i, j;
  138. enum param_type desired_type;
  139. struct tuner_params *t_params;
  140. tun = priv->tun;
  141. /* IFPCoff = Video Intermediate Frequency - Vif:
  142. 940 =16*58.75 NTSC/J (Japan)
  143. 732 =16*45.75 M/N STD
  144. 704 =16*44 ATSC (at DVB code)
  145. 632 =16*39.50 I U.K.
  146. 622.4=16*38.90 B/G D/K I, L STD
  147. 592 =16*37.00 D China
  148. 590 =16.36.875 B Australia
  149. 543.2=16*33.95 L' STD
  150. 171.2=16*10.70 FM Radio (at set_radio_freq)
  151. */
  152. if (params->std == V4L2_STD_NTSC_M_JP) {
  153. IFPCoff = 940;
  154. desired_type = TUNER_PARAM_TYPE_NTSC;
  155. } else if ((params->std & V4L2_STD_MN) &&
  156. !(params->std & ~V4L2_STD_MN)) {
  157. IFPCoff = 732;
  158. desired_type = TUNER_PARAM_TYPE_NTSC;
  159. } else if (params->std == V4L2_STD_SECAM_LC) {
  160. IFPCoff = 543;
  161. desired_type = TUNER_PARAM_TYPE_SECAM;
  162. } else {
  163. IFPCoff = 623;
  164. desired_type = TUNER_PARAM_TYPE_PAL;
  165. }
  166. for (j = 0; j < tun->count-1; j++) {
  167. if (desired_type != tun->params[j].type)
  168. continue;
  169. break;
  170. }
  171. /* use default tuner_t_params if desired_type not available */
  172. if (desired_type != tun->params[j].type) {
  173. tuner_dbg("IFPCoff = %d: tuner_t_params undefined for tuner %d\n",
  174. IFPCoff, priv->type);
  175. j = 0;
  176. }
  177. t_params = &tun->params[j];
  178. for (i = 0; i < t_params->count; i++) {
  179. if (params->frequency > t_params->ranges[i].limit)
  180. continue;
  181. break;
  182. }
  183. if (i == t_params->count) {
  184. tuner_dbg("TV frequency out of range (%d > %d)",
  185. params->frequency, t_params->ranges[i - 1].limit);
  186. params->frequency = t_params->ranges[--i].limit;
  187. }
  188. config = t_params->ranges[i].config;
  189. cb = t_params->ranges[i].cb;
  190. /* i == 0 -> VHF_LO
  191. * i == 1 -> VHF_HI
  192. * i == 2 -> UHF */
  193. tuner_dbg("tv: param %d, range %d\n",j,i);
  194. div=params->frequency + IFPCoff + offset;
  195. tuner_dbg("Freq= %d.%02d MHz, V_IF=%d.%02d MHz, Offset=%d.%02d MHz, div=%0d\n",
  196. params->frequency / 16, params->frequency % 16 * 100 / 16,
  197. IFPCoff / 16, IFPCoff % 16 * 100 / 16,
  198. offset / 16, offset % 16 * 100 / 16,
  199. div);
  200. /* tv norm specific stuff for multi-norm tuners */
  201. switch (priv->type) {
  202. case TUNER_PHILIPS_SECAM: // FI1216MF
  203. /* 0x01 -> ??? no change ??? */
  204. /* 0x02 -> PAL BDGHI / SECAM L */
  205. /* 0x04 -> ??? PAL others / SECAM others ??? */
  206. cb &= ~0x03;
  207. if (params->std & V4L2_STD_SECAM_L) //also valid for V4L2_STD_SECAM
  208. cb |= PHILIPS_MF_SET_STD_L;
  209. else if (params->std & V4L2_STD_SECAM_LC)
  210. cb |= PHILIPS_MF_SET_STD_LC;
  211. else /* V4L2_STD_B|V4L2_STD_GH */
  212. cb |= PHILIPS_MF_SET_STD_BG;
  213. break;
  214. case TUNER_TEMIC_4046FM5:
  215. cb &= ~0x0f;
  216. if (params->std & V4L2_STD_PAL_BG) {
  217. cb |= TEMIC_SET_PAL_BG;
  218. } else if (params->std & V4L2_STD_PAL_I) {
  219. cb |= TEMIC_SET_PAL_I;
  220. } else if (params->std & V4L2_STD_PAL_DK) {
  221. cb |= TEMIC_SET_PAL_DK;
  222. } else if (params->std & V4L2_STD_SECAM_L) {
  223. cb |= TEMIC_SET_PAL_L;
  224. }
  225. break;
  226. case TUNER_PHILIPS_FQ1216ME:
  227. cb &= ~0x0f;
  228. if (params->std & (V4L2_STD_PAL_BG|V4L2_STD_PAL_DK)) {
  229. cb |= PHILIPS_SET_PAL_BGDK;
  230. } else if (params->std & V4L2_STD_PAL_I) {
  231. cb |= PHILIPS_SET_PAL_I;
  232. } else if (params->std & V4L2_STD_SECAM_L) {
  233. cb |= PHILIPS_SET_PAL_L;
  234. }
  235. break;
  236. case TUNER_PHILIPS_ATSC:
  237. /* 0x00 -> ATSC antenna input 1 */
  238. /* 0x01 -> ATSC antenna input 2 */
  239. /* 0x02 -> NTSC antenna input 1 */
  240. /* 0x03 -> NTSC antenna input 2 */
  241. cb &= ~0x03;
  242. if (!(params->std & V4L2_STD_ATSC))
  243. cb |= 2;
  244. /* FIXME: input */
  245. break;
  246. case TUNER_MICROTUNE_4042FI5:
  247. /* Set the charge pump for fast tuning */
  248. config |= TUNER_CHARGE_PUMP;
  249. break;
  250. case TUNER_PHILIPS_TUV1236D:
  251. /* 0x40 -> ATSC antenna input 1 */
  252. /* 0x48 -> ATSC antenna input 2 */
  253. /* 0x00 -> NTSC antenna input 1 */
  254. /* 0x08 -> NTSC antenna input 2 */
  255. buffer[0] = 0x14;
  256. buffer[1] = 0x00;
  257. buffer[2] = 0x17;
  258. buffer[3] = 0x00;
  259. cb &= ~0x40;
  260. if (params->std & V4L2_STD_ATSC) {
  261. cb |= 0x40;
  262. buffer[1] = 0x04;
  263. }
  264. /* set to the correct mode (analog or digital) */
  265. tuneraddr = priv->i2c_props.addr;
  266. priv->i2c_props.addr = 0x0a;
  267. if (2 != (rc = tuner_i2c_xfer_send(&priv->i2c_props,&buffer[0],2)))
  268. tuner_warn("i2c i/o error: rc == %d (should be 2)\n",rc);
  269. if (2 != (rc = tuner_i2c_xfer_send(&priv->i2c_props,&buffer[2],2)))
  270. tuner_warn("i2c i/o error: rc == %d (should be 2)\n",rc);
  271. priv->i2c_props.addr = tuneraddr;
  272. /* FIXME: input */
  273. break;
  274. }
  275. if (t_params->cb_first_if_lower_freq && div < priv->last_div) {
  276. buffer[0] = config;
  277. buffer[1] = cb;
  278. buffer[2] = (div>>8) & 0x7f;
  279. buffer[3] = div & 0xff;
  280. } else {
  281. buffer[0] = (div>>8) & 0x7f;
  282. buffer[1] = div & 0xff;
  283. buffer[2] = config;
  284. buffer[3] = cb;
  285. }
  286. priv->last_div = div;
  287. if (t_params->has_tda9887) {
  288. int config = 0;
  289. int is_secam_l = (params->std & (V4L2_STD_SECAM_L | V4L2_STD_SECAM_LC)) &&
  290. !(params->std & ~(V4L2_STD_SECAM_L | V4L2_STD_SECAM_LC));
  291. if (params->std == V4L2_STD_SECAM_LC) {
  292. if (t_params->port1_active ^ t_params->port1_invert_for_secam_lc)
  293. config |= TDA9887_PORT1_ACTIVE;
  294. if (t_params->port2_active ^ t_params->port2_invert_for_secam_lc)
  295. config |= TDA9887_PORT2_ACTIVE;
  296. }
  297. else {
  298. if (t_params->port1_active)
  299. config |= TDA9887_PORT1_ACTIVE;
  300. if (t_params->port2_active)
  301. config |= TDA9887_PORT2_ACTIVE;
  302. }
  303. if (t_params->intercarrier_mode)
  304. config |= TDA9887_INTERCARRIER;
  305. if (is_secam_l) {
  306. if (i == 0 && t_params->default_top_secam_low)
  307. config |= TDA9887_TOP(t_params->default_top_secam_low);
  308. else if (i == 1 && t_params->default_top_secam_mid)
  309. config |= TDA9887_TOP(t_params->default_top_secam_mid);
  310. else if (t_params->default_top_secam_high)
  311. config |= TDA9887_TOP(t_params->default_top_secam_high);
  312. }
  313. else {
  314. if (i == 0 && t_params->default_top_low)
  315. config |= TDA9887_TOP(t_params->default_top_low);
  316. else if (i == 1 && t_params->default_top_mid)
  317. config |= TDA9887_TOP(t_params->default_top_mid);
  318. else if (t_params->default_top_high)
  319. config |= TDA9887_TOP(t_params->default_top_high);
  320. }
  321. if (t_params->default_pll_gating_18)
  322. config |= TDA9887_GATING_18;
  323. i2c_clients_command(priv->i2c_props.adap, TDA9887_SET_CONFIG, &config);
  324. }
  325. tuner_dbg("tv 0x%02x 0x%02x 0x%02x 0x%02x\n",
  326. buffer[0],buffer[1],buffer[2],buffer[3]);
  327. if (4 != (rc = tuner_i2c_xfer_send(&priv->i2c_props,buffer,4)))
  328. tuner_warn("i2c i/o error: rc == %d (should be 4)\n",rc);
  329. switch (priv->type) {
  330. case TUNER_LG_TDVS_H06XF:
  331. /* Set the Auxiliary Byte. */
  332. buffer[0] = buffer[2];
  333. buffer[0] &= ~0x20;
  334. buffer[0] |= 0x18;
  335. buffer[1] = 0x20;
  336. tuner_dbg("tv 0x%02x 0x%02x\n",buffer[0],buffer[1]);
  337. if (2 != (rc = tuner_i2c_xfer_send(&priv->i2c_props,buffer,2)))
  338. tuner_warn("i2c i/o error: rc == %d (should be 2)\n",rc);
  339. break;
  340. case TUNER_MICROTUNE_4042FI5:
  341. {
  342. // FIXME - this may also work for other tuners
  343. unsigned long timeout = jiffies + msecs_to_jiffies(1);
  344. u8 status_byte = 0;
  345. /* Wait until the PLL locks */
  346. for (;;) {
  347. if (time_after(jiffies,timeout))
  348. return 0;
  349. if (1 != (rc = tuner_i2c_xfer_recv(&priv->i2c_props,&status_byte,1))) {
  350. tuner_warn("i2c i/o read error: rc == %d (should be 1)\n",rc);
  351. break;
  352. }
  353. if (status_byte & TUNER_PLL_LOCKED)
  354. break;
  355. udelay(10);
  356. }
  357. /* Set the charge pump for optimized phase noise figure */
  358. config &= ~TUNER_CHARGE_PUMP;
  359. buffer[0] = (div>>8) & 0x7f;
  360. buffer[1] = div & 0xff;
  361. buffer[2] = config;
  362. buffer[3] = cb;
  363. tuner_dbg("tv 0x%02x 0x%02x 0x%02x 0x%02x\n",
  364. buffer[0],buffer[1],buffer[2],buffer[3]);
  365. if (4 != (rc = tuner_i2c_xfer_send(&priv->i2c_props,buffer,4)))
  366. tuner_warn("i2c i/o error: rc == %d (should be 4)\n",rc);
  367. break;
  368. }
  369. }
  370. return 0;
  371. }
  372. static int simple_set_radio_freq(struct dvb_frontend *fe,
  373. struct analog_parameters *params)
  374. {
  375. struct tunertype *tun;
  376. struct tuner_simple_priv *priv = fe->tuner_priv;
  377. u8 buffer[4];
  378. u16 div;
  379. int rc, j;
  380. struct tuner_params *t_params;
  381. unsigned int freq = params->frequency;
  382. tun = priv->tun;
  383. for (j = tun->count-1; j > 0; j--)
  384. if (tun->params[j].type == TUNER_PARAM_TYPE_RADIO)
  385. break;
  386. /* default t_params (j=0) will be used if desired type wasn't found */
  387. t_params = &tun->params[j];
  388. /* Select Radio 1st IF used */
  389. switch (t_params->radio_if) {
  390. case 0: /* 10.7 MHz */
  391. freq += (unsigned int)(10.7*16000);
  392. break;
  393. case 1: /* 33.3 MHz */
  394. freq += (unsigned int)(33.3*16000);
  395. break;
  396. case 2: /* 41.3 MHz */
  397. freq += (unsigned int)(41.3*16000);
  398. break;
  399. default:
  400. tuner_warn("Unsupported radio_if value %d\n", t_params->radio_if);
  401. return 0;
  402. }
  403. /* Bandswitch byte */
  404. switch (priv->type) {
  405. case TUNER_TENA_9533_DI:
  406. case TUNER_YMEC_TVF_5533MF:
  407. tuner_dbg("This tuner doesn't have FM. Most cards have a TEA5767 for FM\n");
  408. return 0;
  409. case TUNER_PHILIPS_FM1216ME_MK3:
  410. case TUNER_PHILIPS_FM1236_MK3:
  411. case TUNER_PHILIPS_FMD1216ME_MK3:
  412. case TUNER_LG_NTSC_TAPE:
  413. case TUNER_PHILIPS_FM1256_IH3:
  414. buffer[3] = 0x19;
  415. break;
  416. case TUNER_TNF_5335MF:
  417. buffer[3] = 0x11;
  418. break;
  419. case TUNER_LG_PAL_FM:
  420. buffer[3] = 0xa5;
  421. break;
  422. case TUNER_THOMSON_DTT761X:
  423. buffer[3] = 0x39;
  424. break;
  425. case TUNER_MICROTUNE_4049FM5:
  426. default:
  427. buffer[3] = 0xa4;
  428. break;
  429. }
  430. buffer[2] = (t_params->ranges[0].config & ~TUNER_RATIO_MASK) |
  431. TUNER_RATIO_SELECT_50; /* 50 kHz step */
  432. /* Convert from 1/16 kHz V4L steps to 1/20 MHz (=50 kHz) PLL steps
  433. freq * (1 Mhz / 16000 V4L steps) * (20 PLL steps / 1 MHz) =
  434. freq * (1/800) */
  435. div = (freq + 400) / 800;
  436. if (t_params->cb_first_if_lower_freq && div < priv->last_div) {
  437. buffer[0] = buffer[2];
  438. buffer[1] = buffer[3];
  439. buffer[2] = (div>>8) & 0x7f;
  440. buffer[3] = div & 0xff;
  441. } else {
  442. buffer[0] = (div>>8) & 0x7f;
  443. buffer[1] = div & 0xff;
  444. }
  445. tuner_dbg("radio 0x%02x 0x%02x 0x%02x 0x%02x\n",
  446. buffer[0],buffer[1],buffer[2],buffer[3]);
  447. priv->last_div = div;
  448. if (t_params->has_tda9887) {
  449. int config = 0;
  450. if (t_params->port1_active && !t_params->port1_fm_high_sensitivity)
  451. config |= TDA9887_PORT1_ACTIVE;
  452. if (t_params->port2_active && !t_params->port2_fm_high_sensitivity)
  453. config |= TDA9887_PORT2_ACTIVE;
  454. if (t_params->intercarrier_mode)
  455. config |= TDA9887_INTERCARRIER;
  456. /* if (t_params->port1_set_for_fm_mono)
  457. config &= ~TDA9887_PORT1_ACTIVE;*/
  458. if (t_params->fm_gain_normal)
  459. config |= TDA9887_GAIN_NORMAL;
  460. if (t_params->radio_if == 2)
  461. config |= TDA9887_RIF_41_3;
  462. i2c_clients_command(priv->i2c_props.adap, TDA9887_SET_CONFIG, &config);
  463. }
  464. if (4 != (rc = tuner_i2c_xfer_send(&priv->i2c_props,buffer,4)))
  465. tuner_warn("i2c i/o error: rc == %d (should be 4)\n",rc);
  466. return 0;
  467. }
  468. static int simple_set_params(struct dvb_frontend *fe,
  469. struct analog_parameters *params)
  470. {
  471. struct tuner_simple_priv *priv = fe->tuner_priv;
  472. int ret = -EINVAL;
  473. switch (params->mode) {
  474. case V4L2_TUNER_RADIO:
  475. ret = simple_set_radio_freq(fe, params);
  476. priv->frequency = params->frequency * 125 / 2;
  477. break;
  478. case V4L2_TUNER_ANALOG_TV:
  479. case V4L2_TUNER_DIGITAL_TV:
  480. ret = simple_set_tv_freq(fe, params);
  481. priv->frequency = params->frequency * 62500;
  482. break;
  483. }
  484. return ret;
  485. }
  486. static int simple_release(struct dvb_frontend *fe)
  487. {
  488. kfree(fe->tuner_priv);
  489. fe->tuner_priv = NULL;
  490. return 0;
  491. }
  492. static int simple_get_frequency(struct dvb_frontend *fe, u32 *frequency)
  493. {
  494. struct tuner_simple_priv *priv = fe->tuner_priv;
  495. *frequency = priv->frequency;
  496. return 0;
  497. }
  498. static struct dvb_tuner_ops simple_tuner_ops = {
  499. .set_analog_params = simple_set_params,
  500. .release = simple_release,
  501. .get_frequency = simple_get_frequency,
  502. .get_status = simple_get_status,
  503. };
  504. struct dvb_frontend *simple_tuner_attach(struct dvb_frontend *fe,
  505. struct i2c_adapter *i2c_adap,
  506. u8 i2c_addr,
  507. struct simple_tuner_config *cfg)
  508. {
  509. struct tuner_simple_priv *priv = NULL;
  510. priv = kzalloc(sizeof(struct tuner_simple_priv), GFP_KERNEL);
  511. if (priv == NULL)
  512. return NULL;
  513. fe->tuner_priv = priv;
  514. priv->i2c_props.addr = i2c_addr;
  515. priv->i2c_props.adap = i2c_adap;
  516. priv->type = cfg->type;
  517. priv->tun = cfg->tun;
  518. memcpy(&fe->ops.tuner_ops, &simple_tuner_ops, sizeof(struct dvb_tuner_ops));
  519. tuner_info("type set to %d (%s)\n", cfg->type, cfg->tun->name);
  520. strlcpy(fe->ops.tuner_ops.info.name, cfg->tun->name, sizeof(fe->ops.tuner_ops.info.name));
  521. return fe;
  522. }
  523. EXPORT_SYMBOL_GPL(simple_tuner_attach);
  524. MODULE_DESCRIPTION("Simple 4-control-bytes style tuner driver");
  525. MODULE_AUTHOR("Ralph Metzler, Gerd Knorr, Gunther Mayer");
  526. MODULE_LICENSE("GPL");
  527. /*
  528. * Overrides for Emacs so that we follow Linus's tabbing style.
  529. * ---------------------------------------------------------------------------
  530. * Local variables:
  531. * c-basic-offset: 8
  532. * End:
  533. */