mt312.c 18 KB

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