mt312.c 17 KB

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