mt312.c 17 KB

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