mt312.c 18 KB

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