mt312.c 18 KB

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