mt312.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759
  1. /*
  2. Driver for Zarlink VP310/MT312 Satellite Channel Decoder
  3. Copyright (C) 2003 Andreas Oberritter <obi@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. References:
  16. http://products.zarlink.com/product_profiles/MT312.htm
  17. http://products.zarlink.com/product_profiles/SL1935.htm
  18. */
  19. #include <linux/delay.h>
  20. #include <linux/errno.h>
  21. #include <linux/init.h>
  22. #include <linux/kernel.h>
  23. #include <linux/module.h>
  24. #include <linux/string.h>
  25. #include <linux/slab.h>
  26. #include "dvb_frontend.h"
  27. #include "mt312_priv.h"
  28. #include "mt312.h"
  29. struct mt312_state {
  30. struct i2c_adapter *i2c;
  31. /* configuration settings */
  32. const struct mt312_config *config;
  33. struct dvb_frontend frontend;
  34. u8 id;
  35. unsigned long xtal;
  36. u8 freq_mult;
  37. };
  38. static int debug;
  39. #define dprintk(args...) \
  40. do { \
  41. if (debug) \
  42. printk(KERN_DEBUG "mt312: " args); \
  43. } while (0)
  44. #define MT312_PLL_CLK 10000000UL /* 10 MHz */
  45. static int mt312_read(struct mt312_state *state, const enum mt312_reg_addr reg,
  46. u8 *buf, const size_t count)
  47. {
  48. int ret;
  49. struct i2c_msg msg[2];
  50. u8 regbuf[1] = { reg };
  51. msg[0].addr = state->config->demod_address;
  52. msg[0].flags = 0;
  53. msg[0].buf = regbuf;
  54. msg[0].len = 1;
  55. msg[1].addr = state->config->demod_address;
  56. msg[1].flags = I2C_M_RD;
  57. msg[1].buf = buf;
  58. msg[1].len = count;
  59. ret = i2c_transfer(state->i2c, msg, 2);
  60. if (ret != 2) {
  61. printk(KERN_ERR "%s: ret == %d\n", __func__, ret);
  62. return -EREMOTEIO;
  63. }
  64. if (debug) {
  65. int i;
  66. dprintk("R(%d):", reg & 0x7f);
  67. for (i = 0; i < count; i++)
  68. printk(" %02x", buf[i]);
  69. printk("\n");
  70. }
  71. return 0;
  72. }
  73. static int mt312_write(struct mt312_state *state, const enum mt312_reg_addr reg,
  74. const u8 *src, const size_t count)
  75. {
  76. int ret;
  77. u8 buf[count + 1];
  78. struct i2c_msg msg;
  79. if (debug) {
  80. int i;
  81. dprintk("W(%d):", reg & 0x7f);
  82. for (i = 0; i < count; i++)
  83. printk(" %02x", src[i]);
  84. printk("\n");
  85. }
  86. buf[0] = reg;
  87. memcpy(&buf[1], src, count);
  88. msg.addr = state->config->demod_address;
  89. msg.flags = 0;
  90. msg.buf = buf;
  91. msg.len = count + 1;
  92. ret = i2c_transfer(state->i2c, &msg, 1);
  93. if (ret != 1) {
  94. dprintk("%s: ret == %d\n", __func__, ret);
  95. return -EREMOTEIO;
  96. }
  97. return 0;
  98. }
  99. static inline int mt312_readreg(struct mt312_state *state,
  100. const enum mt312_reg_addr reg, u8 *val)
  101. {
  102. return mt312_read(state, reg, val, 1);
  103. }
  104. static inline int mt312_writereg(struct mt312_state *state,
  105. const enum mt312_reg_addr reg, const u8 val)
  106. {
  107. return mt312_write(state, reg, &val, 1);
  108. }
  109. static inline u32 mt312_div(u32 a, u32 b)
  110. {
  111. return (a + (b / 2)) / b;
  112. }
  113. static int mt312_reset(struct mt312_state *state, const u8 full)
  114. {
  115. return mt312_writereg(state, RESET, full ? 0x80 : 0x40);
  116. }
  117. static int mt312_get_inversion(struct mt312_state *state,
  118. fe_spectral_inversion_t *i)
  119. {
  120. int ret;
  121. u8 vit_mode;
  122. ret = mt312_readreg(state, VIT_MODE, &vit_mode);
  123. if (ret < 0)
  124. return ret;
  125. if (vit_mode & 0x80) /* auto inversion was used */
  126. *i = (vit_mode & 0x40) ? INVERSION_ON : INVERSION_OFF;
  127. return 0;
  128. }
  129. static int mt312_get_symbol_rate(struct mt312_state *state, u32 *sr)
  130. {
  131. int ret;
  132. u8 sym_rate_h;
  133. u8 dec_ratio;
  134. u16 sym_rat_op;
  135. u16 monitor;
  136. u8 buf[2];
  137. ret = mt312_readreg(state, SYM_RATE_H, &sym_rate_h);
  138. if (ret < 0)
  139. return ret;
  140. if (sym_rate_h & 0x80) {
  141. /* symbol rate search was used */
  142. ret = mt312_writereg(state, MON_CTRL, 0x03);
  143. if (ret < 0)
  144. return ret;
  145. ret = mt312_read(state, MONITOR_H, buf, sizeof(buf));
  146. if (ret < 0)
  147. return ret;
  148. monitor = (buf[0] << 8) | buf[1];
  149. dprintk("sr(auto) = %u\n",
  150. mt312_div(monitor * 15625, 4));
  151. } else {
  152. ret = mt312_writereg(state, MON_CTRL, 0x05);
  153. if (ret < 0)
  154. return ret;
  155. ret = mt312_read(state, MONITOR_H, buf, sizeof(buf));
  156. if (ret < 0)
  157. return ret;
  158. dec_ratio = ((buf[0] >> 5) & 0x07) * 32;
  159. ret = mt312_read(state, SYM_RAT_OP_H, buf, sizeof(buf));
  160. if (ret < 0)
  161. return ret;
  162. sym_rat_op = (buf[0] << 8) | buf[1];
  163. dprintk("sym_rat_op=%d dec_ratio=%d\n",
  164. sym_rat_op, dec_ratio);
  165. dprintk("*sr(manual) = %lu\n",
  166. (((state->xtal * 8192) / (sym_rat_op + 8192)) *
  167. 2) - dec_ratio);
  168. }
  169. return 0;
  170. }
  171. static int mt312_get_code_rate(struct mt312_state *state, fe_code_rate_t *cr)
  172. {
  173. const fe_code_rate_t fec_tab[8] =
  174. { FEC_1_2, FEC_2_3, FEC_3_4, FEC_5_6, FEC_6_7, FEC_7_8,
  175. FEC_AUTO, FEC_AUTO };
  176. int ret;
  177. u8 fec_status;
  178. ret = mt312_readreg(state, FEC_STATUS, &fec_status);
  179. if (ret < 0)
  180. return ret;
  181. *cr = fec_tab[(fec_status >> 4) & 0x07];
  182. return 0;
  183. }
  184. static int mt312_initfe(struct dvb_frontend *fe)
  185. {
  186. struct mt312_state *state = fe->demodulator_priv;
  187. int ret;
  188. u8 buf[2];
  189. /* wake up */
  190. ret = mt312_writereg(state, CONFIG,
  191. (state->freq_mult == 6 ? 0x88 : 0x8c));
  192. if (ret < 0)
  193. return ret;
  194. /* wait at least 150 usec */
  195. udelay(150);
  196. /* full reset */
  197. ret = mt312_reset(state, 1);
  198. if (ret < 0)
  199. return ret;
  200. /* Per datasheet, write correct values. 09/28/03 ACCJr.
  201. * If we don't do this, we won't get FE_HAS_VITERBI in the VP310. */
  202. {
  203. u8 buf_def[8] = { 0x14, 0x12, 0x03, 0x02,
  204. 0x01, 0x00, 0x00, 0x00 };
  205. ret = mt312_write(state, VIT_SETUP, buf_def, sizeof(buf_def));
  206. if (ret < 0)
  207. return ret;
  208. }
  209. /* SYS_CLK */
  210. buf[0] = mt312_div(state->xtal * state->freq_mult * 2, 1000000);
  211. /* DISEQC_RATIO */
  212. buf[1] = mt312_div(state->xtal, 22000 * 4);
  213. ret = mt312_write(state, SYS_CLK, buf, sizeof(buf));
  214. if (ret < 0)
  215. return ret;
  216. ret = mt312_writereg(state, SNR_THS_HIGH, 0x32);
  217. if (ret < 0)
  218. return ret;
  219. ret = mt312_writereg(state, OP_CTRL, 0x53);
  220. if (ret < 0)
  221. return ret;
  222. /* TS_SW_LIM */
  223. buf[0] = 0x8c;
  224. buf[1] = 0x98;
  225. ret = mt312_write(state, TS_SW_LIM_L, buf, sizeof(buf));
  226. if (ret < 0)
  227. return ret;
  228. ret = mt312_writereg(state, CS_SW_LIM, 0x69);
  229. if (ret < 0)
  230. return ret;
  231. return 0;
  232. }
  233. static int mt312_send_master_cmd(struct dvb_frontend *fe,
  234. struct dvb_diseqc_master_cmd *c)
  235. {
  236. struct mt312_state *state = fe->demodulator_priv;
  237. int ret;
  238. u8 diseqc_mode;
  239. if ((c->msg_len == 0) || (c->msg_len > sizeof(c->msg)))
  240. return -EINVAL;
  241. ret = mt312_readreg(state, DISEQC_MODE, &diseqc_mode);
  242. if (ret < 0)
  243. return ret;
  244. ret = mt312_write(state, (0x80 | DISEQC_INSTR), c->msg, c->msg_len);
  245. if (ret < 0)
  246. return ret;
  247. ret = mt312_writereg(state, DISEQC_MODE,
  248. (diseqc_mode & 0x40) | ((c->msg_len - 1) << 3)
  249. | 0x04);
  250. if (ret < 0)
  251. return ret;
  252. /* is there a better way to wait for message to be transmitted */
  253. msleep(100);
  254. /* set DISEQC_MODE[2:0] to zero if a return message is expected */
  255. if (c->msg[0] & 0x02) {
  256. ret = mt312_writereg(state, DISEQC_MODE, (diseqc_mode & 0x40));
  257. if (ret < 0)
  258. return ret;
  259. }
  260. return 0;
  261. }
  262. static int mt312_send_burst(struct dvb_frontend *fe, const fe_sec_mini_cmd_t c)
  263. {
  264. struct mt312_state *state = fe->demodulator_priv;
  265. const u8 mini_tab[2] = { 0x02, 0x03 };
  266. int ret;
  267. u8 diseqc_mode;
  268. if (c > SEC_MINI_B)
  269. return -EINVAL;
  270. ret = mt312_readreg(state, DISEQC_MODE, &diseqc_mode);
  271. if (ret < 0)
  272. return ret;
  273. ret = mt312_writereg(state, DISEQC_MODE,
  274. (diseqc_mode & 0x40) | mini_tab[c]);
  275. if (ret < 0)
  276. return ret;
  277. return 0;
  278. }
  279. static int mt312_set_tone(struct dvb_frontend *fe, const fe_sec_tone_mode_t t)
  280. {
  281. struct mt312_state *state = fe->demodulator_priv;
  282. const u8 tone_tab[2] = { 0x01, 0x00 };
  283. int ret;
  284. u8 diseqc_mode;
  285. if (t > SEC_TONE_OFF)
  286. return -EINVAL;
  287. ret = mt312_readreg(state, DISEQC_MODE, &diseqc_mode);
  288. if (ret < 0)
  289. return ret;
  290. ret = mt312_writereg(state, DISEQC_MODE,
  291. (diseqc_mode & 0x40) | tone_tab[t]);
  292. if (ret < 0)
  293. return ret;
  294. return 0;
  295. }
  296. static int mt312_set_voltage(struct dvb_frontend *fe, const fe_sec_voltage_t v)
  297. {
  298. struct mt312_state *state = fe->demodulator_priv;
  299. const u8 volt_tab[3] = { 0x00, 0x40, 0x00 };
  300. if (v > SEC_VOLTAGE_OFF)
  301. return -EINVAL;
  302. return mt312_writereg(state, DISEQC_MODE, volt_tab[v]);
  303. }
  304. static int mt312_read_status(struct dvb_frontend *fe, fe_status_t *s)
  305. {
  306. struct mt312_state *state = fe->demodulator_priv;
  307. int ret;
  308. u8 status[3];
  309. *s = 0;
  310. ret = mt312_read(state, QPSK_STAT_H, status, sizeof(status));
  311. if (ret < 0)
  312. return ret;
  313. dprintk("QPSK_STAT_H: 0x%02x, QPSK_STAT_L: 0x%02x,"
  314. " FEC_STATUS: 0x%02x\n", status[0], status[1], status[2]);
  315. if (status[0] & 0xc0)
  316. *s |= FE_HAS_SIGNAL; /* signal noise ratio */
  317. if (status[0] & 0x04)
  318. *s |= FE_HAS_CARRIER; /* qpsk carrier lock */
  319. if (status[2] & 0x02)
  320. *s |= FE_HAS_VITERBI; /* viterbi lock */
  321. if (status[2] & 0x04)
  322. *s |= FE_HAS_SYNC; /* byte align lock */
  323. if (status[0] & 0x01)
  324. *s |= FE_HAS_LOCK; /* qpsk lock */
  325. return 0;
  326. }
  327. static int mt312_read_ber(struct dvb_frontend *fe, u32 *ber)
  328. {
  329. struct mt312_state *state = fe->demodulator_priv;
  330. int ret;
  331. u8 buf[3];
  332. ret = mt312_read(state, RS_BERCNT_H, buf, 3);
  333. if (ret < 0)
  334. return ret;
  335. *ber = ((buf[0] << 16) | (buf[1] << 8) | buf[2]) * 64;
  336. return 0;
  337. }
  338. static int mt312_read_signal_strength(struct dvb_frontend *fe,
  339. u16 *signal_strength)
  340. {
  341. struct mt312_state *state = fe->demodulator_priv;
  342. int ret;
  343. u8 buf[3];
  344. u16 agc;
  345. s16 err_db;
  346. ret = mt312_read(state, AGC_H, buf, sizeof(buf));
  347. if (ret < 0)
  348. return ret;
  349. agc = (buf[0] << 6) | (buf[1] >> 2);
  350. err_db = (s16) (((buf[1] & 0x03) << 14) | buf[2] << 6) >> 6;
  351. *signal_strength = agc;
  352. dprintk("agc=%08x err_db=%hd\n", agc, err_db);
  353. return 0;
  354. }
  355. static int mt312_read_snr(struct dvb_frontend *fe, u16 *snr)
  356. {
  357. struct mt312_state *state = fe->demodulator_priv;
  358. int ret;
  359. u8 buf[2];
  360. ret = mt312_read(state, M_SNR_H, buf, sizeof(buf));
  361. if (ret < 0)
  362. return ret;
  363. *snr = 0xFFFF - ((((buf[0] & 0x7f) << 8) | buf[1]) << 1);
  364. return 0;
  365. }
  366. static int mt312_read_ucblocks(struct dvb_frontend *fe, u32 *ubc)
  367. {
  368. struct mt312_state *state = fe->demodulator_priv;
  369. int ret;
  370. u8 buf[2];
  371. ret = mt312_read(state, RS_UBC_H, buf, sizeof(buf));
  372. if (ret < 0)
  373. return ret;
  374. *ubc = (buf[0] << 8) | buf[1];
  375. return 0;
  376. }
  377. static int mt312_set_frontend(struct dvb_frontend *fe,
  378. struct dvb_frontend_parameters *p)
  379. {
  380. struct mt312_state *state = fe->demodulator_priv;
  381. int ret;
  382. u8 buf[5], config_val;
  383. u16 sr;
  384. const u8 fec_tab[10] =
  385. { 0x00, 0x01, 0x02, 0x04, 0x3f, 0x08, 0x10, 0x20, 0x3f, 0x3f };
  386. const u8 inv_tab[3] = { 0x00, 0x40, 0x80 };
  387. dprintk("%s: Freq %d\n", __func__, p->frequency);
  388. if ((p->frequency < fe->ops.info.frequency_min)
  389. || (p->frequency > fe->ops.info.frequency_max))
  390. return -EINVAL;
  391. if ((p->inversion < INVERSION_OFF)
  392. || (p->inversion > INVERSION_ON))
  393. return -EINVAL;
  394. if ((p->u.qpsk.symbol_rate < fe->ops.info.symbol_rate_min)
  395. || (p->u.qpsk.symbol_rate > fe->ops.info.symbol_rate_max))
  396. return -EINVAL;
  397. if ((p->u.qpsk.fec_inner < FEC_NONE)
  398. || (p->u.qpsk.fec_inner > FEC_AUTO))
  399. return -EINVAL;
  400. if ((p->u.qpsk.fec_inner == FEC_4_5)
  401. || (p->u.qpsk.fec_inner == FEC_8_9))
  402. return -EINVAL;
  403. switch (state->id) {
  404. case ID_VP310:
  405. /* For now we will do this only for the VP310.
  406. * It should be better for the mt312 as well,
  407. * but tuning will be slower. ACCJr 09/29/03
  408. */
  409. ret = mt312_readreg(state, CONFIG, &config_val);
  410. if (ret < 0)
  411. return ret;
  412. if (p->u.qpsk.symbol_rate >= 30000000) {
  413. /* Note that 30MS/s should use 90MHz */
  414. if (state->freq_mult == 6) {
  415. /* We are running 60MHz */
  416. state->freq_mult = 9;
  417. ret = mt312_initfe(fe);
  418. if (ret < 0)
  419. return ret;
  420. }
  421. } else {
  422. if (state->freq_mult == 9) {
  423. /* We are running 90MHz */
  424. state->freq_mult = 6;
  425. ret = mt312_initfe(fe);
  426. if (ret < 0)
  427. return ret;
  428. }
  429. }
  430. break;
  431. case ID_MT312:
  432. break;
  433. default:
  434. return -EINVAL;
  435. }
  436. if (fe->ops.tuner_ops.set_params) {
  437. fe->ops.tuner_ops.set_params(fe, p);
  438. if (fe->ops.i2c_gate_ctrl)
  439. fe->ops.i2c_gate_ctrl(fe, 0);
  440. }
  441. /* sr = (u16)(sr * 256.0 / 1000000.0) */
  442. sr = mt312_div(p->u.qpsk.symbol_rate * 4, 15625);
  443. /* SYM_RATE */
  444. buf[0] = (sr >> 8) & 0x3f;
  445. buf[1] = (sr >> 0) & 0xff;
  446. /* VIT_MODE */
  447. buf[2] = inv_tab[p->inversion] | fec_tab[p->u.qpsk.fec_inner];
  448. /* QPSK_CTRL */
  449. buf[3] = 0x40; /* swap I and Q before QPSK demodulation */
  450. if (p->u.qpsk.symbol_rate < 10000000)
  451. buf[3] |= 0x04; /* use afc mode */
  452. /* GO */
  453. buf[4] = 0x01;
  454. ret = mt312_write(state, SYM_RATE_H, buf, sizeof(buf));
  455. if (ret < 0)
  456. return ret;
  457. mt312_reset(state, 0);
  458. return 0;
  459. }
  460. static int mt312_get_frontend(struct dvb_frontend *fe,
  461. struct dvb_frontend_parameters *p)
  462. {
  463. struct mt312_state *state = fe->demodulator_priv;
  464. int ret;
  465. ret = mt312_get_inversion(state, &p->inversion);
  466. if (ret < 0)
  467. return ret;
  468. ret = mt312_get_symbol_rate(state, &p->u.qpsk.symbol_rate);
  469. if (ret < 0)
  470. return ret;
  471. ret = mt312_get_code_rate(state, &p->u.qpsk.fec_inner);
  472. if (ret < 0)
  473. return ret;
  474. return 0;
  475. }
  476. static int mt312_i2c_gate_ctrl(struct dvb_frontend *fe, int enable)
  477. {
  478. struct mt312_state *state = fe->demodulator_priv;
  479. if (enable) {
  480. return mt312_writereg(state, GPP_CTRL, 0x40);
  481. } else {
  482. return mt312_writereg(state, GPP_CTRL, 0x00);
  483. }
  484. }
  485. static int mt312_sleep(struct dvb_frontend *fe)
  486. {
  487. struct mt312_state *state = fe->demodulator_priv;
  488. int ret;
  489. u8 config;
  490. /* reset all registers to defaults */
  491. ret = mt312_reset(state, 1);
  492. if (ret < 0)
  493. return ret;
  494. ret = mt312_readreg(state, CONFIG, &config);
  495. if (ret < 0)
  496. return ret;
  497. /* enter standby */
  498. ret = mt312_writereg(state, CONFIG, config & 0x7f);
  499. if (ret < 0)
  500. return ret;
  501. return 0;
  502. }
  503. static int mt312_get_tune_settings(struct dvb_frontend *fe,
  504. struct dvb_frontend_tune_settings *fesettings)
  505. {
  506. fesettings->min_delay_ms = 50;
  507. fesettings->step_size = 0;
  508. fesettings->max_drift = 0;
  509. return 0;
  510. }
  511. static void mt312_release(struct dvb_frontend *fe)
  512. {
  513. struct mt312_state *state = fe->demodulator_priv;
  514. kfree(state);
  515. }
  516. #define MT312_SYS_CLK 90000000UL /* 90 MHz */
  517. static struct dvb_frontend_ops vp310_mt312_ops = {
  518. .info = {
  519. .name = "Zarlink ???? DVB-S",
  520. .type = FE_QPSK,
  521. .frequency_min = 950000,
  522. .frequency_max = 2150000,
  523. .frequency_stepsize = (MT312_PLL_CLK / 1000) / 128, /* FIXME: adjust freq to real used xtal */
  524. .symbol_rate_min = MT312_SYS_CLK / 128, /* FIXME as above */
  525. .symbol_rate_max = MT312_SYS_CLK / 2,
  526. .caps =
  527. FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 |
  528. FE_CAN_FEC_3_4 | FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 |
  529. FE_CAN_FEC_AUTO | FE_CAN_QPSK | FE_CAN_MUTE_TS |
  530. FE_CAN_RECOVER
  531. },
  532. .release = mt312_release,
  533. .init = mt312_initfe,
  534. .sleep = mt312_sleep,
  535. .i2c_gate_ctrl = mt312_i2c_gate_ctrl,
  536. .set_frontend = mt312_set_frontend,
  537. .get_frontend = mt312_get_frontend,
  538. .get_tune_settings = mt312_get_tune_settings,
  539. .read_status = mt312_read_status,
  540. .read_ber = mt312_read_ber,
  541. .read_signal_strength = mt312_read_signal_strength,
  542. .read_snr = mt312_read_snr,
  543. .read_ucblocks = mt312_read_ucblocks,
  544. .diseqc_send_master_cmd = mt312_send_master_cmd,
  545. .diseqc_send_burst = mt312_send_burst,
  546. .set_tone = mt312_set_tone,
  547. .set_voltage = mt312_set_voltage,
  548. };
  549. struct dvb_frontend *vp310_mt312_attach(const struct mt312_config *config,
  550. struct i2c_adapter *i2c)
  551. {
  552. struct mt312_state *state = NULL;
  553. /* allocate memory for the internal state */
  554. state = kmalloc(sizeof(struct mt312_state), GFP_KERNEL);
  555. if (state == NULL)
  556. goto error;
  557. /* setup the state */
  558. state->config = config;
  559. state->i2c = i2c;
  560. /* check if the demod is there */
  561. if (mt312_readreg(state, ID, &state->id) < 0)
  562. goto error;
  563. /* create dvb_frontend */
  564. memcpy(&state->frontend.ops, &vp310_mt312_ops,
  565. sizeof(struct dvb_frontend_ops));
  566. state->frontend.demodulator_priv = state;
  567. switch (state->id) {
  568. case ID_VP310:
  569. strcpy(state->frontend.ops.info.name, "Zarlink VP310 DVB-S");
  570. state->xtal = MT312_PLL_CLK;
  571. state->freq_mult = 9;
  572. break;
  573. case ID_MT312:
  574. strcpy(state->frontend.ops.info.name, "Zarlink MT312 DVB-S");
  575. state->xtal = MT312_PLL_CLK;
  576. state->freq_mult = 6;
  577. break;
  578. default:
  579. printk(KERN_WARNING "Only Zarlink VP310/MT312"
  580. " are supported chips.\n");
  581. goto error;
  582. }
  583. return &state->frontend;
  584. error:
  585. kfree(state);
  586. return NULL;
  587. }
  588. EXPORT_SYMBOL(vp310_mt312_attach);
  589. module_param(debug, int, 0644);
  590. MODULE_PARM_DESC(debug, "Turn on/off frontend debugging (default:off).");
  591. MODULE_DESCRIPTION("Zarlink VP310/MT312 DVB-S Demodulator driver");
  592. MODULE_AUTHOR("Andreas Oberritter <obi@linuxtv.org>");
  593. MODULE_LICENSE("GPL");