tda18271-fe.c 17 KB

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