tda10086.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. Driver for Philips tda10086 DVBS Demodulator
  4. (c) 2006 Andrew de Quincey
  5. */
  6. #include <linux/init.h>
  7. #include <linux/module.h>
  8. #include <linux/device.h>
  9. #include <linux/jiffies.h>
  10. #include <linux/string.h>
  11. #include <linux/slab.h>
  12. #include <media/dvb_frontend.h>
  13. #include "tda10086.h"
  14. #define SACLK 96000000
  15. struct tda10086_state {
  16. struct i2c_adapter* i2c;
  17. const struct tda10086_config* config;
  18. struct dvb_frontend frontend;
  19. /* private demod data */
  20. u32 frequency;
  21. u32 symbol_rate;
  22. bool has_lock;
  23. };
  24. static int debug;
  25. #define dprintk(args...) \
  26. do { \
  27. if (debug) printk(KERN_DEBUG "tda10086: " args); \
  28. } while (0)
  29. static int tda10086_write_byte(struct tda10086_state *state, int reg, int data)
  30. {
  31. int ret;
  32. u8 b0[] = { reg, data };
  33. struct i2c_msg msg = { .flags = 0, .buf = b0, .len = 2 };
  34. msg.addr = state->config->demod_address;
  35. ret = i2c_transfer(state->i2c, &msg, 1);
  36. if (ret != 1)
  37. dprintk("%s: error reg=0x%x, data=0x%x, ret=%i\n",
  38. __func__, reg, data, ret);
  39. return (ret != 1) ? ret : 0;
  40. }
  41. static int tda10086_read_byte(struct tda10086_state *state, int reg)
  42. {
  43. int ret;
  44. u8 b0[] = { reg };
  45. u8 b1[] = { 0 };
  46. struct i2c_msg msg[] = {{ .flags = 0, .buf = b0, .len = 1 },
  47. { .flags = I2C_M_RD, .buf = b1, .len = 1 }};
  48. msg[0].addr = state->config->demod_address;
  49. msg[1].addr = state->config->demod_address;
  50. ret = i2c_transfer(state->i2c, msg, 2);
  51. if (ret != 2) {
  52. dprintk("%s: error reg=0x%x, ret=%i\n", __func__, reg,
  53. ret);
  54. return ret;
  55. }
  56. return b1[0];
  57. }
  58. static int tda10086_write_mask(struct tda10086_state *state, int reg, int mask, int data)
  59. {
  60. int val;
  61. /* read a byte and check */
  62. val = tda10086_read_byte(state, reg);
  63. if (val < 0)
  64. return val;
  65. /* mask if off */
  66. val = val & ~mask;
  67. val |= data & 0xff;
  68. /* write it out again */
  69. return tda10086_write_byte(state, reg, val);
  70. }
  71. static int tda10086_init(struct dvb_frontend* fe)
  72. {
  73. struct tda10086_state* state = fe->demodulator_priv;
  74. u8 t22k_off = 0x80;
  75. dprintk ("%s\n", __func__);
  76. if (state->config->diseqc_tone)
  77. t22k_off = 0;
  78. /* reset */
  79. tda10086_write_byte(state, 0x00, 0x00);
  80. msleep(10);
  81. /* misc setup */
  82. tda10086_write_byte(state, 0x01, 0x94);
  83. tda10086_write_byte(state, 0x02, 0x35); /* NOTE: TT drivers appear to disable CSWP */
  84. tda10086_write_byte(state, 0x03, 0xe4);
  85. tda10086_write_byte(state, 0x04, 0x43);
  86. tda10086_write_byte(state, 0x0c, 0x0c);
  87. tda10086_write_byte(state, 0x1b, 0xb0); /* noise threshold */
  88. tda10086_write_byte(state, 0x20, 0x89); /* misc */
  89. tda10086_write_byte(state, 0x30, 0x04); /* acquisition period length */
  90. tda10086_write_byte(state, 0x32, 0x00); /* irq off */
  91. tda10086_write_byte(state, 0x31, 0x56); /* setup AFC */
  92. /* setup PLL (this assumes SACLK = 96MHz) */
  93. tda10086_write_byte(state, 0x55, 0x2c); /* misc PLL setup */
  94. if (state->config->xtal_freq == TDA10086_XTAL_16M) {
  95. tda10086_write_byte(state, 0x3a, 0x0b); /* M=12 */
  96. tda10086_write_byte(state, 0x3b, 0x01); /* P=2 */
  97. } else {
  98. tda10086_write_byte(state, 0x3a, 0x17); /* M=24 */
  99. tda10086_write_byte(state, 0x3b, 0x00); /* P=1 */
  100. }
  101. tda10086_write_mask(state, 0x55, 0x20, 0x00); /* powerup PLL */
  102. /* setup TS interface */
  103. tda10086_write_byte(state, 0x11, 0x81);
  104. tda10086_write_byte(state, 0x12, 0x81);
  105. tda10086_write_byte(state, 0x19, 0x40); /* parallel mode A + MSBFIRST */
  106. tda10086_write_byte(state, 0x56, 0x80); /* powerdown WPLL - unused in the mode we use */
  107. tda10086_write_byte(state, 0x57, 0x08); /* bypass WPLL - unused in the mode we use */
  108. tda10086_write_byte(state, 0x10, 0x2a);
  109. /* setup ADC */
  110. tda10086_write_byte(state, 0x58, 0x61); /* ADC setup */
  111. tda10086_write_mask(state, 0x58, 0x01, 0x00); /* powerup ADC */
  112. /* setup AGC */
  113. tda10086_write_byte(state, 0x05, 0x0B);
  114. tda10086_write_byte(state, 0x37, 0x63);
  115. tda10086_write_byte(state, 0x3f, 0x0a); /* NOTE: flydvb varies it */
  116. tda10086_write_byte(state, 0x40, 0x64);
  117. tda10086_write_byte(state, 0x41, 0x4f);
  118. tda10086_write_byte(state, 0x42, 0x43);
  119. /* setup viterbi */
  120. tda10086_write_byte(state, 0x1a, 0x11); /* VBER 10^6, DVB, QPSK */
  121. /* setup carrier recovery */
  122. tda10086_write_byte(state, 0x3d, 0x80);
  123. /* setup SEC */
  124. tda10086_write_byte(state, 0x36, t22k_off); /* all SEC off, 22k tone */
  125. tda10086_write_byte(state, 0x34, (((1<<19) * (22000/1000)) / (SACLK/1000)));
  126. tda10086_write_byte(state, 0x35, (((1<<19) * (22000/1000)) / (SACLK/1000)) >> 8);
  127. return 0;
  128. }
  129. static void tda10086_diseqc_wait(struct tda10086_state *state)
  130. {
  131. unsigned long timeout = jiffies + msecs_to_jiffies(200);
  132. while (!(tda10086_read_byte(state, 0x50) & 0x01)) {
  133. if(time_after(jiffies, timeout)) {
  134. printk("%s: diseqc queue not ready, command may be lost.\n", __func__);
  135. break;
  136. }
  137. msleep(10);
  138. }
  139. }
  140. static int tda10086_set_tone(struct dvb_frontend *fe,
  141. enum fe_sec_tone_mode tone)
  142. {
  143. struct tda10086_state* state = fe->demodulator_priv;
  144. u8 t22k_off = 0x80;
  145. dprintk ("%s\n", __func__);
  146. if (state->config->diseqc_tone)
  147. t22k_off = 0;
  148. switch (tone) {
  149. case SEC_TONE_OFF:
  150. tda10086_write_byte(state, 0x36, t22k_off);
  151. break;
  152. case SEC_TONE_ON:
  153. tda10086_write_byte(state, 0x36, 0x01 + t22k_off);
  154. break;
  155. }
  156. return 0;
  157. }
  158. static int tda10086_send_master_cmd (struct dvb_frontend* fe,
  159. struct dvb_diseqc_master_cmd* cmd)
  160. {
  161. struct tda10086_state* state = fe->demodulator_priv;
  162. int i;
  163. u8 oldval;
  164. u8 t22k_off = 0x80;
  165. dprintk ("%s\n", __func__);
  166. if (state->config->diseqc_tone)
  167. t22k_off = 0;
  168. if (cmd->msg_len > 6)
  169. return -EINVAL;
  170. oldval = tda10086_read_byte(state, 0x36);
  171. for(i=0; i< cmd->msg_len; i++) {
  172. tda10086_write_byte(state, 0x48+i, cmd->msg[i]);
  173. }
  174. tda10086_write_byte(state, 0x36, (0x08 + t22k_off)
  175. | ((cmd->msg_len - 1) << 4));
  176. tda10086_diseqc_wait(state);
  177. tda10086_write_byte(state, 0x36, oldval);
  178. return 0;
  179. }
  180. static int tda10086_send_burst(struct dvb_frontend *fe,
  181. enum fe_sec_mini_cmd minicmd)
  182. {
  183. struct tda10086_state* state = fe->demodulator_priv;
  184. u8 oldval = tda10086_read_byte(state, 0x36);
  185. u8 t22k_off = 0x80;
  186. dprintk ("%s\n", __func__);
  187. if (state->config->diseqc_tone)
  188. t22k_off = 0;
  189. switch(minicmd) {
  190. case SEC_MINI_A:
  191. tda10086_write_byte(state, 0x36, 0x04 + t22k_off);
  192. break;
  193. case SEC_MINI_B:
  194. tda10086_write_byte(state, 0x36, 0x06 + t22k_off);
  195. break;
  196. }
  197. tda10086_diseqc_wait(state);
  198. tda10086_write_byte(state, 0x36, oldval);
  199. return 0;
  200. }
  201. static int tda10086_set_inversion(struct tda10086_state *state,
  202. struct dtv_frontend_properties *fe_params)
  203. {
  204. u8 invval = 0x80;
  205. dprintk ("%s %i %i\n", __func__, fe_params->inversion, state->config->invert);
  206. switch(fe_params->inversion) {
  207. case INVERSION_OFF:
  208. if (state->config->invert)
  209. invval = 0x40;
  210. break;
  211. case INVERSION_ON:
  212. if (!state->config->invert)
  213. invval = 0x40;
  214. break;
  215. case INVERSION_AUTO:
  216. invval = 0x00;
  217. break;
  218. }
  219. tda10086_write_mask(state, 0x0c, 0xc0, invval);
  220. return 0;
  221. }
  222. static int tda10086_set_symbol_rate(struct tda10086_state *state,
  223. struct dtv_frontend_properties *fe_params)
  224. {
  225. u8 dfn = 0;
  226. u8 afs = 0;
  227. u8 byp = 0;
  228. u8 reg37 = 0x43;
  229. u8 reg42 = 0x43;
  230. u64 big;
  231. u32 tmp;
  232. u32 bdr;
  233. u32 bdri;
  234. u32 symbol_rate = fe_params->symbol_rate;
  235. dprintk ("%s %i\n", __func__, symbol_rate);
  236. /* setup the decimation and anti-aliasing filters.. */
  237. if (symbol_rate < (u32) (SACLK * 0.0137)) {
  238. dfn=4;
  239. afs=1;
  240. } else if (symbol_rate < (u32) (SACLK * 0.0208)) {
  241. dfn=4;
  242. afs=0;
  243. } else if (symbol_rate < (u32) (SACLK * 0.0270)) {
  244. dfn=3;
  245. afs=1;
  246. } else if (symbol_rate < (u32) (SACLK * 0.0416)) {
  247. dfn=3;
  248. afs=0;
  249. } else if (symbol_rate < (u32) (SACLK * 0.0550)) {
  250. dfn=2;
  251. afs=1;
  252. } else if (symbol_rate < (u32) (SACLK * 0.0833)) {
  253. dfn=2;
  254. afs=0;
  255. } else if (symbol_rate < (u32) (SACLK * 0.1100)) {
  256. dfn=1;
  257. afs=1;
  258. } else if (symbol_rate < (u32) (SACLK * 0.1666)) {
  259. dfn=1;
  260. afs=0;
  261. } else if (symbol_rate < (u32) (SACLK * 0.2200)) {
  262. dfn=0;
  263. afs=1;
  264. } else if (symbol_rate < (u32) (SACLK * 0.3333)) {
  265. dfn=0;
  266. afs=0;
  267. } else {
  268. reg37 = 0x63;
  269. reg42 = 0x4f;
  270. byp=1;
  271. }
  272. /* calculate BDR */
  273. big = (1ULL<<21) * ((u64) symbol_rate/1000ULL) * (1ULL<<dfn);
  274. big += ((SACLK/1000ULL)-1ULL);
  275. do_div(big, (SACLK/1000ULL));
  276. bdr = big & 0xfffff;
  277. /* calculate BDRI */
  278. tmp = (1<<dfn)*(symbol_rate/1000);
  279. bdri = ((32 * (SACLK/1000)) + (tmp-1)) / tmp;
  280. tda10086_write_byte(state, 0x21, (afs << 7) | dfn);
  281. tda10086_write_mask(state, 0x20, 0x08, byp << 3);
  282. tda10086_write_byte(state, 0x06, bdr);
  283. tda10086_write_byte(state, 0x07, bdr >> 8);
  284. tda10086_write_byte(state, 0x08, bdr >> 16);
  285. tda10086_write_byte(state, 0x09, bdri);
  286. tda10086_write_byte(state, 0x37, reg37);
  287. tda10086_write_byte(state, 0x42, reg42);
  288. return 0;
  289. }
  290. static int tda10086_set_fec(struct tda10086_state *state,
  291. struct dtv_frontend_properties *fe_params)
  292. {
  293. u8 fecval;
  294. dprintk("%s %i\n", __func__, fe_params->fec_inner);
  295. switch (fe_params->fec_inner) {
  296. case FEC_1_2:
  297. fecval = 0x00;
  298. break;
  299. case FEC_2_3:
  300. fecval = 0x01;
  301. break;
  302. case FEC_3_4:
  303. fecval = 0x02;
  304. break;
  305. case FEC_4_5:
  306. fecval = 0x03;
  307. break;
  308. case FEC_5_6:
  309. fecval = 0x04;
  310. break;
  311. case FEC_6_7:
  312. fecval = 0x05;
  313. break;
  314. case FEC_7_8:
  315. fecval = 0x06;
  316. break;
  317. case FEC_8_9:
  318. fecval = 0x07;
  319. break;
  320. case FEC_AUTO:
  321. fecval = 0x08;
  322. break;
  323. default:
  324. return -1;
  325. }
  326. tda10086_write_byte(state, 0x0d, fecval);
  327. return 0;
  328. }
  329. static int tda10086_set_frontend(struct dvb_frontend *fe)
  330. {
  331. struct dtv_frontend_properties *fe_params = &fe->dtv_property_cache;
  332. struct tda10086_state *state = fe->demodulator_priv;
  333. int ret;
  334. u32 freq = 0;
  335. int freqoff;
  336. dprintk ("%s\n", __func__);
  337. /* modify parameters for tuning */
  338. tda10086_write_byte(state, 0x02, 0x35);
  339. state->has_lock = false;
  340. /* set params */
  341. if (fe->ops.tuner_ops.set_params) {
  342. fe->ops.tuner_ops.set_params(fe);
  343. if (fe->ops.i2c_gate_ctrl)
  344. fe->ops.i2c_gate_ctrl(fe, 0);
  345. if (fe->ops.tuner_ops.get_frequency)
  346. fe->ops.tuner_ops.get_frequency(fe, &freq);
  347. if (fe->ops.i2c_gate_ctrl)
  348. fe->ops.i2c_gate_ctrl(fe, 0);
  349. }
  350. /* calculate the frequency offset (in *Hz* not kHz) */
  351. freqoff = fe_params->frequency - freq;
  352. freqoff = ((1<<16) * freqoff) / (SACLK/1000);
  353. tda10086_write_byte(state, 0x3d, 0x80 | ((freqoff >> 8) & 0x7f));
  354. tda10086_write_byte(state, 0x3e, freqoff);
  355. if ((ret = tda10086_set_inversion(state, fe_params)) < 0)
  356. return ret;
  357. if ((ret = tda10086_set_symbol_rate(state, fe_params)) < 0)
  358. return ret;
  359. if ((ret = tda10086_set_fec(state, fe_params)) < 0)
  360. return ret;
  361. /* soft reset + disable TS output until lock */
  362. tda10086_write_mask(state, 0x10, 0x40, 0x40);
  363. tda10086_write_mask(state, 0x00, 0x01, 0x00);
  364. state->symbol_rate = fe_params->symbol_rate;
  365. state->frequency = fe_params->frequency;
  366. return 0;
  367. }
  368. static int tda10086_get_frontend(struct dvb_frontend *fe,
  369. struct dtv_frontend_properties *fe_params)
  370. {
  371. struct tda10086_state* state = fe->demodulator_priv;
  372. u8 val;
  373. int tmp;
  374. u64 tmp64;
  375. dprintk ("%s\n", __func__);
  376. /* check for invalid symbol rate */
  377. if (fe_params->symbol_rate < 500000)
  378. return -EINVAL;
  379. /* calculate the updated frequency (note: we convert from Hz->kHz) */
  380. tmp64 = ((u64)tda10086_read_byte(state, 0x52)
  381. | (tda10086_read_byte(state, 0x51) << 8));
  382. if (tmp64 & 0x8000)
  383. tmp64 |= 0xffffffffffff0000ULL;
  384. tmp64 = (tmp64 * (SACLK/1000ULL));
  385. do_div(tmp64, (1ULL<<15) * (1ULL<<1));
  386. fe_params->frequency = (int) state->frequency + (int) tmp64;
  387. /* the inversion */
  388. val = tda10086_read_byte(state, 0x0c);
  389. if (val & 0x80) {
  390. switch(val & 0x40) {
  391. case 0x00:
  392. fe_params->inversion = INVERSION_OFF;
  393. if (state->config->invert)
  394. fe_params->inversion = INVERSION_ON;
  395. break;
  396. default:
  397. fe_params->inversion = INVERSION_ON;
  398. if (state->config->invert)
  399. fe_params->inversion = INVERSION_OFF;
  400. break;
  401. }
  402. } else {
  403. tda10086_read_byte(state, 0x0f);
  404. switch(val & 0x02) {
  405. case 0x00:
  406. fe_params->inversion = INVERSION_OFF;
  407. if (state->config->invert)
  408. fe_params->inversion = INVERSION_ON;
  409. break;
  410. default:
  411. fe_params->inversion = INVERSION_ON;
  412. if (state->config->invert)
  413. fe_params->inversion = INVERSION_OFF;
  414. break;
  415. }
  416. }
  417. /* calculate the updated symbol rate */
  418. tmp = tda10086_read_byte(state, 0x1d);
  419. if (tmp & 0x80)
  420. tmp |= 0xffffff00;
  421. tmp = (tmp * 480 * (1<<1)) / 128;
  422. tmp = ((state->symbol_rate/1000) * tmp) / (1000000/1000);
  423. fe_params->symbol_rate = state->symbol_rate + tmp;
  424. /* the FEC */
  425. val = (tda10086_read_byte(state, 0x0d) & 0x70) >> 4;
  426. switch(val) {
  427. case 0x00:
  428. fe_params->fec_inner = FEC_1_2;
  429. break;
  430. case 0x01:
  431. fe_params->fec_inner = FEC_2_3;
  432. break;
  433. case 0x02:
  434. fe_params->fec_inner = FEC_3_4;
  435. break;
  436. case 0x03:
  437. fe_params->fec_inner = FEC_4_5;
  438. break;
  439. case 0x04:
  440. fe_params->fec_inner = FEC_5_6;
  441. break;
  442. case 0x05:
  443. fe_params->fec_inner = FEC_6_7;
  444. break;
  445. case 0x06:
  446. fe_params->fec_inner = FEC_7_8;
  447. break;
  448. case 0x07:
  449. fe_params->fec_inner = FEC_8_9;
  450. break;
  451. }
  452. return 0;
  453. }
  454. static int tda10086_read_status(struct dvb_frontend *fe,
  455. enum fe_status *fe_status)
  456. {
  457. struct tda10086_state* state = fe->demodulator_priv;
  458. u8 val;
  459. dprintk ("%s\n", __func__);
  460. val = tda10086_read_byte(state, 0x0e);
  461. *fe_status = 0;
  462. if (val & 0x01)
  463. *fe_status |= FE_HAS_SIGNAL;
  464. if (val & 0x02)
  465. *fe_status |= FE_HAS_CARRIER;
  466. if (val & 0x04)
  467. *fe_status |= FE_HAS_VITERBI;
  468. if (val & 0x08)
  469. *fe_status |= FE_HAS_SYNC;
  470. if (val & 0x10) {
  471. *fe_status |= FE_HAS_LOCK;
  472. if (!state->has_lock) {
  473. state->has_lock = true;
  474. /* modify parameters for stable reception */
  475. tda10086_write_byte(state, 0x02, 0x00);
  476. }
  477. }
  478. return 0;
  479. }
  480. static int tda10086_read_signal_strength(struct dvb_frontend* fe, u16 * signal)
  481. {
  482. struct tda10086_state* state = fe->demodulator_priv;
  483. u8 _str;
  484. dprintk ("%s\n", __func__);
  485. _str = 0xff - tda10086_read_byte(state, 0x43);
  486. *signal = (_str << 8) | _str;
  487. return 0;
  488. }
  489. static int tda10086_read_snr(struct dvb_frontend* fe, u16 * snr)
  490. {
  491. struct tda10086_state* state = fe->demodulator_priv;
  492. u8 _snr;
  493. dprintk ("%s\n", __func__);
  494. _snr = 0xff - tda10086_read_byte(state, 0x1c);
  495. *snr = (_snr << 8) | _snr;
  496. return 0;
  497. }
  498. static int tda10086_read_ucblocks(struct dvb_frontend* fe, u32* ucblocks)
  499. {
  500. struct tda10086_state* state = fe->demodulator_priv;
  501. dprintk ("%s\n", __func__);
  502. /* read it */
  503. *ucblocks = tda10086_read_byte(state, 0x18) & 0x7f;
  504. /* reset counter */
  505. tda10086_write_byte(state, 0x18, 0x00);
  506. tda10086_write_byte(state, 0x18, 0x80);
  507. return 0;
  508. }
  509. static int tda10086_read_ber(struct dvb_frontend* fe, u32* ber)
  510. {
  511. struct tda10086_state* state = fe->demodulator_priv;
  512. dprintk ("%s\n", __func__);
  513. /* read it */
  514. *ber = 0;
  515. *ber |= tda10086_read_byte(state, 0x15);
  516. *ber |= tda10086_read_byte(state, 0x16) << 8;
  517. *ber |= (tda10086_read_byte(state, 0x17) & 0xf) << 16;
  518. return 0;
  519. }
  520. static int tda10086_sleep(struct dvb_frontend* fe)
  521. {
  522. struct tda10086_state* state = fe->demodulator_priv;
  523. dprintk ("%s\n", __func__);
  524. tda10086_write_mask(state, 0x00, 0x08, 0x08);
  525. return 0;
  526. }
  527. static int tda10086_i2c_gate_ctrl(struct dvb_frontend* fe, int enable)
  528. {
  529. struct tda10086_state* state = fe->demodulator_priv;
  530. dprintk ("%s\n", __func__);
  531. if (enable) {
  532. tda10086_write_mask(state, 0x00, 0x10, 0x10);
  533. } else {
  534. tda10086_write_mask(state, 0x00, 0x10, 0x00);
  535. }
  536. return 0;
  537. }
  538. static int tda10086_get_tune_settings(struct dvb_frontend* fe, struct dvb_frontend_tune_settings* fesettings)
  539. {
  540. struct dtv_frontend_properties *p = &fe->dtv_property_cache;
  541. if (p->symbol_rate > 20000000) {
  542. fesettings->min_delay_ms = 50;
  543. fesettings->step_size = 2000;
  544. fesettings->max_drift = 8000;
  545. } else if (p->symbol_rate > 12000000) {
  546. fesettings->min_delay_ms = 100;
  547. fesettings->step_size = 1500;
  548. fesettings->max_drift = 9000;
  549. } else if (p->symbol_rate > 8000000) {
  550. fesettings->min_delay_ms = 100;
  551. fesettings->step_size = 1000;
  552. fesettings->max_drift = 8000;
  553. } else if (p->symbol_rate > 4000000) {
  554. fesettings->min_delay_ms = 100;
  555. fesettings->step_size = 500;
  556. fesettings->max_drift = 7000;
  557. } else if (p->symbol_rate > 2000000) {
  558. fesettings->min_delay_ms = 200;
  559. fesettings->step_size = p->symbol_rate / 8000;
  560. fesettings->max_drift = 14 * fesettings->step_size;
  561. } else {
  562. fesettings->min_delay_ms = 200;
  563. fesettings->step_size = p->symbol_rate / 8000;
  564. fesettings->max_drift = 18 * fesettings->step_size;
  565. }
  566. return 0;
  567. }
  568. static void tda10086_release(struct dvb_frontend* fe)
  569. {
  570. struct tda10086_state *state = fe->demodulator_priv;
  571. tda10086_sleep(fe);
  572. kfree(state);
  573. }
  574. static const struct dvb_frontend_ops tda10086_ops = {
  575. .delsys = { SYS_DVBS },
  576. .info = {
  577. .name = "Philips TDA10086 DVB-S",
  578. .frequency_min_hz = 950 * MHz,
  579. .frequency_max_hz = 2150 * MHz,
  580. .frequency_stepsize_hz = 125 * kHz,
  581. .symbol_rate_min = 1000000,
  582. .symbol_rate_max = 45000000,
  583. .caps = FE_CAN_INVERSION_AUTO |
  584. FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
  585. FE_CAN_FEC_5_6 | FE_CAN_FEC_6_7 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO |
  586. FE_CAN_QPSK
  587. },
  588. .release = tda10086_release,
  589. .init = tda10086_init,
  590. .sleep = tda10086_sleep,
  591. .i2c_gate_ctrl = tda10086_i2c_gate_ctrl,
  592. .set_frontend = tda10086_set_frontend,
  593. .get_frontend = tda10086_get_frontend,
  594. .get_tune_settings = tda10086_get_tune_settings,
  595. .read_status = tda10086_read_status,
  596. .read_ber = tda10086_read_ber,
  597. .read_signal_strength = tda10086_read_signal_strength,
  598. .read_snr = tda10086_read_snr,
  599. .read_ucblocks = tda10086_read_ucblocks,
  600. .diseqc_send_master_cmd = tda10086_send_master_cmd,
  601. .diseqc_send_burst = tda10086_send_burst,
  602. .set_tone = tda10086_set_tone,
  603. };
  604. struct dvb_frontend* tda10086_attach(const struct tda10086_config* config,
  605. struct i2c_adapter* i2c)
  606. {
  607. struct tda10086_state *state;
  608. dprintk ("%s\n", __func__);
  609. /* allocate memory for the internal state */
  610. state = kzalloc(sizeof(struct tda10086_state), GFP_KERNEL);
  611. if (!state)
  612. return NULL;
  613. /* setup the state */
  614. state->config = config;
  615. state->i2c = i2c;
  616. /* check if the demod is there */
  617. if (tda10086_read_byte(state, 0x1e) != 0xe1) {
  618. kfree(state);
  619. return NULL;
  620. }
  621. /* create dvb_frontend */
  622. memcpy(&state->frontend.ops, &tda10086_ops, sizeof(struct dvb_frontend_ops));
  623. state->frontend.demodulator_priv = state;
  624. return &state->frontend;
  625. }
  626. module_param(debug, int, 0644);
  627. MODULE_PARM_DESC(debug, "Turn on/off frontend debugging (default:off).");
  628. MODULE_DESCRIPTION("Philips TDA10086 DVB-S Demodulator");
  629. MODULE_AUTHOR("Andrew de Quincey");
  630. MODULE_LICENSE("GPL");
  631. EXPORT_SYMBOL(tda10086_attach);