tda18271-fe.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748
  1. /*
  2. tda18271-fe.c - driver for the Philips / NXP TDA18271 silicon tuner
  3. Copyright (C) 2007 Michael Krufky (mkrufky@linuxtv.org)
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. */
  16. #include <linux/delay.h>
  17. #include <linux/videodev2.h>
  18. #include "tuner-driver.h"
  19. #include "tda18271.h"
  20. #include "tda18271-priv.h"
  21. int tda18271_debug;
  22. module_param_named(debug, tda18271_debug, int, 0644);
  23. MODULE_PARM_DESC(debug, "set debug level (info=1, map=2, reg=4 (or-able))");
  24. /*---------------------------------------------------------------------*/
  25. enum tda18271_mode {
  26. TDA18271_ANALOG,
  27. TDA18271_DIGITAL,
  28. };
  29. struct tda18271_priv {
  30. u8 i2c_addr;
  31. struct i2c_adapter *i2c_adap;
  32. unsigned char tda18271_regs[TDA18271_NUM_REGS];
  33. enum tda18271_mode mode;
  34. u32 frequency;
  35. u32 bandwidth;
  36. };
  37. static int tda18271_i2c_gate_ctrl(struct dvb_frontend *fe, int enable)
  38. {
  39. struct tda18271_priv *priv = fe->tuner_priv;
  40. struct analog_tuner_ops *ops = fe->ops.analog_demod_ops;
  41. int ret = 0;
  42. switch (priv->mode) {
  43. case TDA18271_ANALOG:
  44. if (ops && ops->i2c_gate_ctrl)
  45. ret = ops->i2c_gate_ctrl(fe, enable);
  46. break;
  47. case TDA18271_DIGITAL:
  48. if (fe->ops.i2c_gate_ctrl)
  49. ret = fe->ops.i2c_gate_ctrl(fe, enable);
  50. break;
  51. }
  52. return ret;
  53. };
  54. /*---------------------------------------------------------------------*/
  55. static void tda18271_dump_regs(struct dvb_frontend *fe)
  56. {
  57. struct tda18271_priv *priv = fe->tuner_priv;
  58. unsigned char *regs = priv->tda18271_regs;
  59. dbg_reg("=== TDA18271 REG DUMP ===\n");
  60. dbg_reg("ID_BYTE = 0x%02x\n", 0xff & regs[R_ID]);
  61. dbg_reg("THERMO_BYTE = 0x%02x\n", 0xff & regs[R_TM]);
  62. dbg_reg("POWER_LEVEL_BYTE = 0x%02x\n", 0xff & regs[R_PL]);
  63. dbg_reg("EASY_PROG_BYTE_1 = 0x%02x\n", 0xff & regs[R_EP1]);
  64. dbg_reg("EASY_PROG_BYTE_2 = 0x%02x\n", 0xff & regs[R_EP2]);
  65. dbg_reg("EASY_PROG_BYTE_3 = 0x%02x\n", 0xff & regs[R_EP3]);
  66. dbg_reg("EASY_PROG_BYTE_4 = 0x%02x\n", 0xff & regs[R_EP4]);
  67. dbg_reg("EASY_PROG_BYTE_5 = 0x%02x\n", 0xff & regs[R_EP5]);
  68. dbg_reg("CAL_POST_DIV_BYTE = 0x%02x\n", 0xff & regs[R_CPD]);
  69. dbg_reg("CAL_DIV_BYTE_1 = 0x%02x\n", 0xff & regs[R_CD1]);
  70. dbg_reg("CAL_DIV_BYTE_2 = 0x%02x\n", 0xff & regs[R_CD2]);
  71. dbg_reg("CAL_DIV_BYTE_3 = 0x%02x\n", 0xff & regs[R_CD3]);
  72. dbg_reg("MAIN_POST_DIV_BYTE = 0x%02x\n", 0xff & regs[R_MPD]);
  73. dbg_reg("MAIN_DIV_BYTE_1 = 0x%02x\n", 0xff & regs[R_MD1]);
  74. dbg_reg("MAIN_DIV_BYTE_2 = 0x%02x\n", 0xff & regs[R_MD2]);
  75. dbg_reg("MAIN_DIV_BYTE_3 = 0x%02x\n", 0xff & regs[R_MD3]);
  76. }
  77. static void tda18271_read_regs(struct dvb_frontend *fe)
  78. {
  79. struct tda18271_priv *priv = fe->tuner_priv;
  80. unsigned char *regs = priv->tda18271_regs;
  81. unsigned char buf = 0x00;
  82. int ret;
  83. struct i2c_msg msg[] = {
  84. { .addr = priv->i2c_addr, .flags = 0,
  85. .buf = &buf, .len = 1 },
  86. { .addr = priv->i2c_addr, .flags = I2C_M_RD,
  87. .buf = regs, .len = 16 }
  88. };
  89. tda18271_i2c_gate_ctrl(fe, 1);
  90. /* read all registers */
  91. ret = i2c_transfer(priv->i2c_adap, msg, 2);
  92. tda18271_i2c_gate_ctrl(fe, 0);
  93. if (ret != 2)
  94. printk("ERROR: %s: i2c_transfer returned: %d\n",
  95. __FUNCTION__, ret);
  96. if (tda18271_debug & DBG_REG)
  97. tda18271_dump_regs(fe);
  98. }
  99. static void tda18271_write_regs(struct dvb_frontend *fe, int idx, int len)
  100. {
  101. struct tda18271_priv *priv = fe->tuner_priv;
  102. unsigned char *regs = priv->tda18271_regs;
  103. unsigned char buf[TDA18271_NUM_REGS+1];
  104. struct i2c_msg msg = { .addr = priv->i2c_addr, .flags = 0,
  105. .buf = buf, .len = len+1 };
  106. int i, ret;
  107. BUG_ON((len == 0) || (idx+len > sizeof(buf)));
  108. buf[0] = idx;
  109. for (i = 1; i <= len; i++) {
  110. buf[i] = regs[idx-1+i];
  111. }
  112. tda18271_i2c_gate_ctrl(fe, 1);
  113. /* write registers */
  114. ret = i2c_transfer(priv->i2c_adap, &msg, 1);
  115. tda18271_i2c_gate_ctrl(fe, 0);
  116. if (ret != 1)
  117. printk(KERN_WARNING "ERROR: %s: i2c_transfer returned: %d\n",
  118. __FUNCTION__, ret);
  119. }
  120. /*---------------------------------------------------------------------*/
  121. static int tda18271_init_regs(struct dvb_frontend *fe)
  122. {
  123. struct tda18271_priv *priv = fe->tuner_priv;
  124. unsigned char *regs = priv->tda18271_regs;
  125. printk(KERN_INFO "tda18271: initializing registers\n");
  126. /* initialize registers */
  127. regs[R_ID] = 0x83;
  128. regs[R_TM] = 0x08;
  129. regs[R_PL] = 0x80;
  130. regs[R_EP1] = 0xc6;
  131. regs[R_EP2] = 0xdf;
  132. regs[R_EP3] = 0x16;
  133. regs[R_EP4] = 0x60;
  134. regs[R_EP5] = 0x80;
  135. regs[R_CPD] = 0x80;
  136. regs[R_CD1] = 0x00;
  137. regs[R_CD2] = 0x00;
  138. regs[R_CD3] = 0x00;
  139. regs[R_MPD] = 0x00;
  140. regs[R_MD1] = 0x00;
  141. regs[R_MD2] = 0x00;
  142. regs[R_MD3] = 0x00;
  143. regs[R_EB1] = 0xff;
  144. regs[R_EB2] = 0x01;
  145. regs[R_EB3] = 0x84;
  146. regs[R_EB4] = 0x41;
  147. regs[R_EB5] = 0x01;
  148. regs[R_EB6] = 0x84;
  149. regs[R_EB7] = 0x40;
  150. regs[R_EB8] = 0x07;
  151. regs[R_EB9] = 0x00;
  152. regs[R_EB10] = 0x00;
  153. regs[R_EB11] = 0x96;
  154. regs[R_EB12] = 0x0f;
  155. regs[R_EB13] = 0xc1;
  156. regs[R_EB14] = 0x00;
  157. regs[R_EB15] = 0x8f;
  158. regs[R_EB16] = 0x00;
  159. regs[R_EB17] = 0x00;
  160. regs[R_EB18] = 0x00;
  161. regs[R_EB19] = 0x00;
  162. regs[R_EB20] = 0x20;
  163. regs[R_EB21] = 0x33;
  164. regs[R_EB22] = 0x48;
  165. regs[R_EB23] = 0xb0;
  166. tda18271_write_regs(fe, 0x00, TDA18271_NUM_REGS);
  167. /* setup AGC1 & AGC2 */
  168. regs[R_EB17] = 0x00;
  169. tda18271_write_regs(fe, R_EB17, 1);
  170. regs[R_EB17] = 0x03;
  171. tda18271_write_regs(fe, R_EB17, 1);
  172. regs[R_EB17] = 0x43;
  173. tda18271_write_regs(fe, R_EB17, 1);
  174. regs[R_EB17] = 0x4c;
  175. tda18271_write_regs(fe, R_EB17, 1);
  176. regs[R_EB20] = 0xa0;
  177. tda18271_write_regs(fe, R_EB20, 1);
  178. regs[R_EB20] = 0xa7;
  179. tda18271_write_regs(fe, R_EB20, 1);
  180. regs[R_EB20] = 0xe7;
  181. tda18271_write_regs(fe, R_EB20, 1);
  182. regs[R_EB20] = 0xec;
  183. tda18271_write_regs(fe, R_EB20, 1);
  184. /* image rejection calibration */
  185. /* low-band */
  186. regs[R_EP3] = 0x1f;
  187. regs[R_EP4] = 0x66;
  188. regs[R_EP5] = 0x81;
  189. regs[R_CPD] = 0xcc;
  190. regs[R_CD1] = 0x6c;
  191. regs[R_CD2] = 0x00;
  192. regs[R_CD3] = 0x00;
  193. regs[R_MPD] = 0xcd;
  194. regs[R_MD1] = 0x77;
  195. regs[R_MD2] = 0x08;
  196. regs[R_MD3] = 0x00;
  197. tda18271_write_regs(fe, R_EP3, 11);
  198. msleep(5); /* pll locking */
  199. regs[R_EP1] = 0xc6;
  200. tda18271_write_regs(fe, R_EP1, 1);
  201. msleep(5); /* wanted low measurement */
  202. regs[R_EP3] = 0x1f;
  203. regs[R_EP4] = 0x66;
  204. regs[R_EP5] = 0x85;
  205. regs[R_CPD] = 0xcb;
  206. regs[R_CD1] = 0x66;
  207. regs[R_CD2] = 0x70;
  208. regs[R_CD3] = 0x00;
  209. tda18271_write_regs(fe, R_EP3, 7);
  210. msleep(5); /* pll locking */
  211. regs[R_EP2] = 0xdf;
  212. tda18271_write_regs(fe, R_EP2, 1);
  213. msleep(30); /* image low optimization completion */
  214. /* mid-band */
  215. regs[R_EP3] = 0x1f;
  216. regs[R_EP4] = 0x66;
  217. regs[R_EP5] = 0x82;
  218. regs[R_CPD] = 0xa8;
  219. regs[R_CD1] = 0x66;
  220. regs[R_CD2] = 0x00;
  221. regs[R_CD3] = 0x00;
  222. regs[R_MPD] = 0xa9;
  223. regs[R_MD1] = 0x73;
  224. regs[R_MD2] = 0x1a;
  225. regs[R_MD3] = 0x00;
  226. tda18271_write_regs(fe, R_EP3, 11);
  227. msleep(5); /* pll locking */
  228. regs[R_EP1] = 0xc6;
  229. tda18271_write_regs(fe, R_EP1, 1);
  230. msleep(5); /* wanted mid measurement */
  231. regs[R_EP3] = 0x1f;
  232. regs[R_EP4] = 0x66;
  233. regs[R_EP5] = 0x86;
  234. regs[R_CPD] = 0xa8;
  235. regs[R_CD1] = 0x66;
  236. regs[R_CD2] = 0xa0;
  237. regs[R_CD3] = 0x00;
  238. tda18271_write_regs(fe, R_EP3, 7);
  239. msleep(5); /* pll locking */
  240. regs[R_EP2] = 0xdf;
  241. tda18271_write_regs(fe, R_EP2, 1);
  242. msleep(30); /* image mid optimization completion */
  243. /* high-band */
  244. regs[R_EP3] = 0x1f;
  245. regs[R_EP4] = 0x66;
  246. regs[R_EP5] = 0x83;
  247. regs[R_CPD] = 0x98;
  248. regs[R_CD1] = 0x65;
  249. regs[R_CD2] = 0x00;
  250. regs[R_CD3] = 0x00;
  251. regs[R_MPD] = 0x99;
  252. regs[R_MD1] = 0x71;
  253. regs[R_MD2] = 0xcd;
  254. regs[R_MD3] = 0x00;
  255. tda18271_write_regs(fe, R_EP3, 11);
  256. msleep(5); /* pll locking */
  257. regs[R_EP1] = 0xc6;
  258. tda18271_write_regs(fe, R_EP1, 1);
  259. msleep(5); /* wanted high measurement */
  260. regs[R_EP3] = 0x1f;
  261. regs[R_EP4] = 0x66;
  262. regs[R_EP5] = 0x87;
  263. regs[R_CPD] = 0x98;
  264. regs[R_CD1] = 0x65;
  265. regs[R_CD2] = 0x50;
  266. regs[R_CD3] = 0x00;
  267. tda18271_write_regs(fe, R_EP3, 7);
  268. msleep(5); /* pll locking */
  269. regs[R_EP2] = 0xdf;
  270. tda18271_write_regs(fe, R_EP2, 1);
  271. msleep(30); /* image high optimization completion */
  272. regs[R_EP4] = 0x64;
  273. tda18271_write_regs(fe, R_EP4, 1);
  274. regs[R_EP1] = 0xc6;
  275. tda18271_write_regs(fe, R_EP1, 1);
  276. return 0;
  277. }
  278. static int tda18271_init(struct dvb_frontend *fe)
  279. {
  280. struct tda18271_priv *priv = fe->tuner_priv;
  281. unsigned char *regs = priv->tda18271_regs;
  282. tda18271_read_regs(fe);
  283. /* test IR_CAL_OK to see if we need init */
  284. if ((regs[R_EP1] & 0x08) == 0)
  285. tda18271_init_regs(fe);
  286. return 0;
  287. }
  288. static int tda18271_tune(struct dvb_frontend *fe,
  289. u32 ifc, u32 freq, u32 bw, u8 std)
  290. {
  291. struct tda18271_priv *priv = fe->tuner_priv;
  292. unsigned char *regs = priv->tda18271_regs;
  293. u32 div, N = 0;
  294. u8 d, pd, val;
  295. tda18271_init(fe);
  296. dbg_info("freq = %d, ifc = %d\n", freq, ifc);
  297. /* RF tracking filter calibration */
  298. /* calculate BP_Filter */
  299. tda18271_calc_bp_filter(&freq, &val);
  300. regs[R_EP1] &= ~0x07; /* clear bp filter bits */
  301. regs[R_EP1] |= val;
  302. tda18271_write_regs(fe, R_EP1, 1);
  303. regs[R_EB4] &= 0x07;
  304. regs[R_EB4] |= 0x60;
  305. tda18271_write_regs(fe, R_EB4, 1);
  306. regs[R_EB7] = 0x60;
  307. tda18271_write_regs(fe, R_EB7, 1);
  308. regs[R_EB14] = 0x00;
  309. tda18271_write_regs(fe, R_EB14, 1);
  310. regs[R_EB20] = 0xcc;
  311. tda18271_write_regs(fe, R_EB20, 1);
  312. /* set CAL mode to RF tracking filter calibration */
  313. regs[R_EB4] |= 0x03;
  314. /* calculate CAL PLL */
  315. switch (priv->mode) {
  316. case TDA18271_ANALOG:
  317. N = freq - 1250000;
  318. break;
  319. case TDA18271_DIGITAL:
  320. N = freq + bw / 2;
  321. break;
  322. }
  323. tda18271_calc_cal_pll(&N, &pd, &d);
  324. regs[R_CPD] = pd;
  325. div = ((d * (N / 1000)) << 7) / 125;
  326. regs[R_CD1] = 0xff & (div >> 16);
  327. regs[R_CD2] = 0xff & (div >> 8);
  328. regs[R_CD3] = 0xff & div;
  329. /* calculate MAIN PLL */
  330. switch (priv->mode) {
  331. case TDA18271_ANALOG:
  332. N = freq - 250000;
  333. break;
  334. case TDA18271_DIGITAL:
  335. N = freq + bw / 2 + 1000000;
  336. break;
  337. }
  338. tda18271_calc_main_pll(&N, &pd, &d);
  339. regs[R_MPD] = (0x7f & pd);
  340. switch (priv->mode) {
  341. case TDA18271_ANALOG:
  342. regs[R_MPD] &= ~0x08;
  343. break;
  344. case TDA18271_DIGITAL:
  345. regs[R_MPD] |= 0x08;
  346. break;
  347. }
  348. div = ((d * (N / 1000)) << 7) / 125;
  349. regs[R_MD1] = 0xff & (div >> 16);
  350. regs[R_MD2] = 0xff & (div >> 8);
  351. regs[R_MD3] = 0xff & div;
  352. tda18271_write_regs(fe, R_EP3, 11);
  353. msleep(5); /* RF tracking filter calibration initialization */
  354. /* search for K,M,CO for RF Calibration */
  355. tda18271_calc_km(&freq, &val);
  356. regs[R_EB13] &= 0x83;
  357. regs[R_EB13] |= val;
  358. tda18271_write_regs(fe, R_EB13, 1);
  359. /* search for RF_BAND */
  360. tda18271_calc_rf_band(&freq, &val);
  361. regs[R_EP2] &= ~0xe0; /* clear rf band bits */
  362. regs[R_EP2] |= (val << 5);
  363. /* search for Gain_Taper */
  364. tda18271_calc_gain_taper(&freq, &val);
  365. regs[R_EP2] &= ~0x1f; /* clear gain taper bits */
  366. regs[R_EP2] |= val;
  367. tda18271_write_regs(fe, R_EP2, 1);
  368. tda18271_write_regs(fe, R_EP1, 1);
  369. tda18271_write_regs(fe, R_EP2, 1);
  370. tda18271_write_regs(fe, R_EP1, 1);
  371. regs[R_EB4] &= 0x07;
  372. regs[R_EB4] |= 0x40;
  373. tda18271_write_regs(fe, R_EB4, 1);
  374. regs[R_EB7] = 0x40;
  375. tda18271_write_regs(fe, R_EB7, 1);
  376. msleep(10);
  377. regs[R_EB20] = 0xec;
  378. tda18271_write_regs(fe, R_EB20, 1);
  379. msleep(60); /* RF tracking filter calibration completion */
  380. regs[R_EP4] &= ~0x03; /* set cal mode to normal */
  381. tda18271_write_regs(fe, R_EP4, 1);
  382. tda18271_write_regs(fe, R_EP1, 1);
  383. /* RF tracking filer correction for VHF_Low band */
  384. tda18271_calc_rf_cal(&freq, &val);
  385. /* VHF_Low band only */
  386. if (val != 0) {
  387. regs[R_EB14] = val;
  388. tda18271_write_regs(fe, R_EB14, 1);
  389. }
  390. /* Channel Configuration */
  391. switch (priv->mode) {
  392. case TDA18271_ANALOG:
  393. regs[R_EB22] = 0x2c;
  394. break;
  395. case TDA18271_DIGITAL:
  396. regs[R_EB22] = 0x37;
  397. break;
  398. }
  399. tda18271_write_regs(fe, R_EB22, 1);
  400. regs[R_EP1] |= 0x40; /* set dis power level on */
  401. /* set standard */
  402. regs[R_EP3] &= ~0x1f; /* clear std bits */
  403. /* see table 22 */
  404. regs[R_EP3] |= std;
  405. regs[R_EP4] &= ~0x03; /* set cal mode to normal */
  406. regs[R_EP4] &= ~0x1c; /* clear if level bits */
  407. switch (priv->mode) {
  408. case TDA18271_ANALOG:
  409. regs[R_MPD] &= ~0x80; /* IF notch = 0 */
  410. break;
  411. case TDA18271_DIGITAL:
  412. regs[R_EP4] |= 0x04;
  413. regs[R_MPD] |= 0x80;
  414. break;
  415. }
  416. regs[R_EP4] &= ~0x80; /* turn this bit on only for fm */
  417. /* image rejection validity EP5[2:0] */
  418. tda18271_calc_ir_measure(&freq, &val);
  419. regs[R_EP5] &= ~0x07;
  420. regs[R_EP5] |= val;
  421. /* calculate MAIN PLL */
  422. N = freq + ifc;
  423. tda18271_calc_main_pll(&N, &pd, &d);
  424. regs[R_MPD] = (0x7f & pd);
  425. switch (priv->mode) {
  426. case TDA18271_ANALOG:
  427. regs[R_MPD] &= ~0x08;
  428. break;
  429. case TDA18271_DIGITAL:
  430. regs[R_MPD] |= 0x08;
  431. break;
  432. }
  433. div = ((d * (N / 1000)) << 7) / 125;
  434. regs[R_MD1] = 0xff & (div >> 16);
  435. regs[R_MD2] = 0xff & (div >> 8);
  436. regs[R_MD3] = 0xff & div;
  437. tda18271_write_regs(fe, R_TM, 15);
  438. msleep(5);
  439. return 0;
  440. }
  441. /* ------------------------------------------------------------------ */
  442. static int tda18271_set_params(struct dvb_frontend *fe,
  443. struct dvb_frontend_parameters *params)
  444. {
  445. struct tda18271_priv *priv = fe->tuner_priv;
  446. u8 std;
  447. u32 bw, sgIF = 0;
  448. u32 freq = params->frequency;
  449. priv->mode = TDA18271_DIGITAL;
  450. /* see table 22 */
  451. if (fe->ops.info.type == FE_ATSC) {
  452. switch (params->u.vsb.modulation) {
  453. case VSB_8:
  454. case VSB_16:
  455. std = 0x1b; /* device-specific (spec says 0x1c) */
  456. sgIF = 5380000;
  457. break;
  458. case QAM_64:
  459. case QAM_256:
  460. std = 0x18; /* device-specific (spec says 0x1d) */
  461. sgIF = 4000000;
  462. break;
  463. default:
  464. printk(KERN_WARNING "%s: modulation not set!\n",
  465. __FUNCTION__);
  466. return -EINVAL;
  467. }
  468. #if 0
  469. /* userspace request is already center adjusted */
  470. freq += 1750000; /* Adjust to center (+1.75MHZ) */
  471. #endif
  472. bw = 6000000;
  473. } else if (fe->ops.info.type == FE_OFDM) {
  474. switch (params->u.ofdm.bandwidth) {
  475. case BANDWIDTH_6_MHZ:
  476. std = 0x1b; /* device-specific (spec says 0x1c) */
  477. bw = 6000000;
  478. sgIF = 3300000;
  479. break;
  480. case BANDWIDTH_7_MHZ:
  481. std = 0x19; /* device-specific (spec says 0x1d) */
  482. bw = 7000000;
  483. sgIF = 3800000;
  484. break;
  485. case BANDWIDTH_8_MHZ:
  486. std = 0x1a; /* device-specific (spec says 0x1e) */
  487. bw = 8000000;
  488. sgIF = 4300000;
  489. break;
  490. default:
  491. printk(KERN_WARNING "%s: bandwidth not set!\n",
  492. __FUNCTION__);
  493. return -EINVAL;
  494. }
  495. } else {
  496. printk(KERN_WARNING "%s: modulation type not supported!\n",
  497. __FUNCTION__);
  498. return -EINVAL;
  499. }
  500. return tda18271_tune(fe, sgIF, freq, bw, std);
  501. }
  502. static int tda18271_set_analog_params(struct dvb_frontend *fe,
  503. struct analog_parameters *params)
  504. {
  505. struct tda18271_priv *priv = fe->tuner_priv;
  506. u8 std;
  507. unsigned int sgIF;
  508. char *mode;
  509. priv->mode = TDA18271_ANALOG;
  510. /* see table 22 */
  511. if (params->std & V4L2_STD_MN) {
  512. std = 0x0d;
  513. sgIF = 92;
  514. mode = "MN";
  515. } else if (params->std & V4L2_STD_B) {
  516. std = 0x0e;
  517. sgIF = 108;
  518. mode = "B";
  519. } else if (params->std & V4L2_STD_GH) {
  520. std = 0x0f;
  521. sgIF = 124;
  522. mode = "GH";
  523. } else if (params->std & V4L2_STD_PAL_I) {
  524. std = 0x0f;
  525. sgIF = 124;
  526. mode = "I";
  527. } else if (params->std & V4L2_STD_DK) {
  528. std = 0x0f;
  529. sgIF = 124;
  530. mode = "DK";
  531. } else if (params->std & V4L2_STD_SECAM_L) {
  532. std = 0x0f;
  533. sgIF = 124;
  534. mode = "L";
  535. } else if (params->std & V4L2_STD_SECAM_LC) {
  536. std = 0x0f;
  537. sgIF = 20;
  538. mode = "LC";
  539. } else {
  540. std = 0x0f;
  541. sgIF = 124;
  542. mode = "xx";
  543. }
  544. if (params->mode == V4L2_TUNER_RADIO)
  545. sgIF = 88; /* if frequency is 5.5 MHz */
  546. dbg_info("setting tda18271 to system %s\n", mode);
  547. return tda18271_tune(fe, sgIF * 62500, params->frequency * 62500,
  548. 0, std);
  549. }
  550. static int tda18271_release(struct dvb_frontend *fe)
  551. {
  552. kfree(fe->tuner_priv);
  553. fe->tuner_priv = NULL;
  554. return 0;
  555. }
  556. static int tda18271_get_frequency(struct dvb_frontend *fe, u32 *frequency)
  557. {
  558. struct tda18271_priv *priv = fe->tuner_priv;
  559. *frequency = priv->frequency;
  560. return 0;
  561. }
  562. static int tda18271_get_bandwidth(struct dvb_frontend *fe, u32 *bandwidth)
  563. {
  564. struct tda18271_priv *priv = fe->tuner_priv;
  565. *bandwidth = priv->bandwidth;
  566. return 0;
  567. }
  568. static struct dvb_tuner_ops tda18271_tuner_ops = {
  569. .info = {
  570. .name = "NXP TDA18271HD",
  571. .frequency_min = 45000000,
  572. .frequency_max = 864000000,
  573. .frequency_step = 62500
  574. },
  575. .init = tda18271_init,
  576. .set_params = tda18271_set_params,
  577. .set_analog_params = tda18271_set_analog_params,
  578. .release = tda18271_release,
  579. .get_frequency = tda18271_get_frequency,
  580. .get_bandwidth = tda18271_get_bandwidth,
  581. };
  582. struct dvb_frontend *tda18271_attach(struct dvb_frontend *fe, u8 addr,
  583. struct i2c_adapter *i2c)
  584. {
  585. struct tda18271_priv *priv = NULL;
  586. dbg_info("@ %d-%04x\n", i2c_adapter_id(i2c), addr);
  587. priv = kzalloc(sizeof(struct tda18271_priv), GFP_KERNEL);
  588. if (priv == NULL)
  589. return NULL;
  590. priv->i2c_addr = addr;
  591. priv->i2c_adap = i2c;
  592. memcpy(&fe->ops.tuner_ops, &tda18271_tuner_ops,
  593. sizeof(struct dvb_tuner_ops));
  594. fe->tuner_priv = priv;
  595. tda18271_init_regs(fe);
  596. return fe;
  597. }
  598. EXPORT_SYMBOL_GPL(tda18271_attach);
  599. MODULE_DESCRIPTION("NXP TDA18271HD analog / digital tuner driver");
  600. MODULE_AUTHOR("Michael Krufky <mkrufky@linuxtv.org>");
  601. MODULE_LICENSE("GPL");
  602. /*
  603. * Overrides for Emacs so that we follow Linus's tabbing style.
  604. * ---------------------------------------------------------------------------
  605. * Local variables:
  606. * c-basic-offset: 8
  607. * End:
  608. */