mt312.c 16 KB

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