mt312.c 18 KB

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