2 * Montage M88DS3103 demodulator driver
4 * Copyright (C) 2013 Antti Palosaari <crope@iki.fi>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
17 #include "m88ds3103_priv.h"
19 static struct dvb_frontend_ops m88ds3103_ops
;
21 /* write multiple registers */
22 static int m88ds3103_wr_regs(struct m88ds3103_priv
*priv
,
23 u8 reg
, const u8
*val
, int len
)
26 #define MAX_WR_XFER_LEN (MAX_WR_LEN + 1)
28 u8 buf
[MAX_WR_XFER_LEN
];
29 struct i2c_msg msg
[1] = {
31 .addr
= priv
->cfg
->i2c_addr
,
38 if (WARN_ON(len
> MAX_WR_LEN
))
42 memcpy(&buf
[1], val
, len
);
44 mutex_lock(&priv
->i2c_mutex
);
45 ret
= i2c_transfer(priv
->i2c
, msg
, 1);
46 mutex_unlock(&priv
->i2c_mutex
);
50 dev_warn(&priv
->i2c
->dev
,
51 "%s: i2c wr failed=%d reg=%02x len=%d\n",
52 KBUILD_MODNAME
, ret
, reg
, len
);
59 /* read multiple registers */
60 static int m88ds3103_rd_regs(struct m88ds3103_priv
*priv
,
61 u8 reg
, u8
*val
, int len
)
64 #define MAX_RD_XFER_LEN (MAX_RD_LEN)
66 u8 buf
[MAX_RD_XFER_LEN
];
67 struct i2c_msg msg
[2] = {
69 .addr
= priv
->cfg
->i2c_addr
,
74 .addr
= priv
->cfg
->i2c_addr
,
81 if (WARN_ON(len
> MAX_RD_LEN
))
84 mutex_lock(&priv
->i2c_mutex
);
85 ret
= i2c_transfer(priv
->i2c
, msg
, 2);
86 mutex_unlock(&priv
->i2c_mutex
);
88 memcpy(val
, buf
, len
);
91 dev_warn(&priv
->i2c
->dev
,
92 "%s: i2c rd failed=%d reg=%02x len=%d\n",
93 KBUILD_MODNAME
, ret
, reg
, len
);
100 /* write single register */
101 static int m88ds3103_wr_reg(struct m88ds3103_priv
*priv
, u8 reg
, u8 val
)
103 return m88ds3103_wr_regs(priv
, reg
, &val
, 1);
106 /* read single register */
107 static int m88ds3103_rd_reg(struct m88ds3103_priv
*priv
, u8 reg
, u8
*val
)
109 return m88ds3103_rd_regs(priv
, reg
, val
, 1);
112 /* write single register with mask */
113 static int m88ds3103_wr_reg_mask(struct m88ds3103_priv
*priv
,
114 u8 reg
, u8 val
, u8 mask
)
119 /* no need for read if whole reg is written */
121 ret
= m88ds3103_rd_regs(priv
, reg
, &u8tmp
, 1);
130 return m88ds3103_wr_regs(priv
, reg
, &val
, 1);
133 /* read single register with mask */
134 static int m88ds3103_rd_reg_mask(struct m88ds3103_priv
*priv
,
135 u8 reg
, u8
*val
, u8 mask
)
140 ret
= m88ds3103_rd_regs(priv
, reg
, &u8tmp
, 1);
146 /* find position of the first bit */
147 for (i
= 0; i
< 8; i
++) {
148 if ((mask
>> i
) & 0x01)
156 /* write reg val table using reg addr auto increment */
157 static int m88ds3103_wr_reg_val_tab(struct m88ds3103_priv
*priv
,
158 const struct m88ds3103_reg_val
*tab
, int tab_len
)
162 dev_dbg(&priv
->i2c
->dev
, "%s: tab_len=%d\n", __func__
, tab_len
);
169 for (i
= 0, j
= 0; i
< tab_len
; i
++, j
++) {
172 if (i
== tab_len
- 1 || tab
[i
].reg
!= tab
[i
+ 1].reg
- 1 ||
173 !((j
+ 1) % (priv
->cfg
->i2c_wr_max
- 1))) {
174 ret
= m88ds3103_wr_regs(priv
, tab
[i
].reg
- j
, buf
, j
+ 1);
184 dev_dbg(&priv
->i2c
->dev
, "%s: failed=%d\n", __func__
, ret
);
188 static int m88ds3103_read_status(struct dvb_frontend
*fe
, fe_status_t
*status
)
190 struct m88ds3103_priv
*priv
= fe
->demodulator_priv
;
191 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
202 switch (c
->delivery_system
) {
204 ret
= m88ds3103_rd_reg_mask(priv
, 0xd1, &u8tmp
, 0x07);
209 *status
= FE_HAS_SIGNAL
| FE_HAS_CARRIER
|
210 FE_HAS_VITERBI
| FE_HAS_SYNC
|
214 ret
= m88ds3103_rd_reg_mask(priv
, 0x0d, &u8tmp
, 0x8f);
219 *status
= FE_HAS_SIGNAL
| FE_HAS_CARRIER
|
220 FE_HAS_VITERBI
| FE_HAS_SYNC
|
224 dev_dbg(&priv
->i2c
->dev
, "%s: invalid delivery_system\n",
230 priv
->fe_status
= *status
;
232 dev_dbg(&priv
->i2c
->dev
, "%s: lock=%02x status=%02x\n",
233 __func__
, u8tmp
, *status
);
237 dev_dbg(&priv
->i2c
->dev
, "%s: failed=%d\n", __func__
, ret
);
241 static int m88ds3103_set_frontend(struct dvb_frontend
*fe
)
243 struct m88ds3103_priv
*priv
= fe
->demodulator_priv
;
244 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
246 const struct m88ds3103_reg_val
*init
;
247 u8 u8tmp
, u8tmp1
, u8tmp2
;
249 u16 u16tmp
, divide_ratio
;
250 u32 tuner_frequency
, target_mclk
, ts_clk
;
252 dev_dbg(&priv
->i2c
->dev
,
253 "%s: delivery_system=%d modulation=%d frequency=%d symbol_rate=%d inversion=%d pilot=%d rolloff=%d\n",
254 __func__
, c
->delivery_system
,
255 c
->modulation
, c
->frequency
, c
->symbol_rate
,
256 c
->inversion
, c
->pilot
, c
->rolloff
);
264 if (fe
->ops
.tuner_ops
.set_params
) {
265 ret
= fe
->ops
.tuner_ops
.set_params(fe
);
270 if (fe
->ops
.tuner_ops
.get_frequency
) {
271 ret
= fe
->ops
.tuner_ops
.get_frequency(fe
, &tuner_frequency
);
276 * Use nominal target frequency as tuner driver does not provide
277 * actual frequency used. Carrier offset calculation is not
280 tuner_frequency
= c
->frequency
;
284 ret
= m88ds3103_wr_reg(priv
, 0x07, 0x80);
288 ret
= m88ds3103_wr_reg(priv
, 0x07, 0x00);
292 ret
= m88ds3103_wr_reg(priv
, 0xb2, 0x01);
296 ret
= m88ds3103_wr_reg(priv
, 0x00, 0x01);
300 switch (c
->delivery_system
) {
302 len
= ARRAY_SIZE(m88ds3103_dvbs_init_reg_vals
);
303 init
= m88ds3103_dvbs_init_reg_vals
;
307 len
= ARRAY_SIZE(m88ds3103_dvbs2_init_reg_vals
);
308 init
= m88ds3103_dvbs2_init_reg_vals
;
310 switch (priv
->cfg
->ts_mode
) {
311 case M88DS3103_TS_SERIAL
:
312 case M88DS3103_TS_SERIAL_D7
:
313 if (c
->symbol_rate
< 18000000)
316 target_mclk
= 144000;
318 case M88DS3103_TS_PARALLEL
:
319 case M88DS3103_TS_PARALLEL_12
:
320 case M88DS3103_TS_PARALLEL_16
:
321 case M88DS3103_TS_PARALLEL_19_2
:
322 case M88DS3103_TS_CI
:
323 if (c
->symbol_rate
< 18000000)
325 else if (c
->symbol_rate
< 28000000)
326 target_mclk
= 144000;
328 target_mclk
= 192000;
331 dev_dbg(&priv
->i2c
->dev
, "%s: invalid ts_mode\n",
338 dev_dbg(&priv
->i2c
->dev
, "%s: invalid delivery_system\n",
344 /* program init table */
345 if (c
->delivery_system
!= priv
->delivery_system
) {
346 ret
= m88ds3103_wr_reg_val_tab(priv
, init
, len
);
351 u8tmp1
= 0; /* silence compiler warning */
352 switch (priv
->cfg
->ts_mode
) {
353 case M88DS3103_TS_SERIAL
:
358 case M88DS3103_TS_SERIAL_D7
:
363 case M88DS3103_TS_PARALLEL
:
367 case M88DS3103_TS_PARALLEL_12
:
371 case M88DS3103_TS_PARALLEL_16
:
375 case M88DS3103_TS_PARALLEL_19_2
:
379 case M88DS3103_TS_CI
:
384 dev_dbg(&priv
->i2c
->dev
, "%s: invalid ts_mode\n", __func__
);
390 ret
= m88ds3103_wr_reg(priv
, 0xfd, u8tmp
);
394 switch (priv
->cfg
->ts_mode
) {
395 case M88DS3103_TS_SERIAL
:
396 case M88DS3103_TS_SERIAL_D7
:
397 ret
= m88ds3103_wr_reg_mask(priv
, 0x29, u8tmp1
, 0x20);
403 divide_ratio
= DIV_ROUND_UP(target_mclk
, ts_clk
);
404 u8tmp1
= divide_ratio
/ 2;
405 u8tmp2
= DIV_ROUND_UP(divide_ratio
, 2);
412 dev_dbg(&priv
->i2c
->dev
,
413 "%s: target_mclk=%d ts_clk=%d divide_ratio=%d\n",
414 __func__
, target_mclk
, ts_clk
, divide_ratio
);
418 /* u8tmp1[5:2] => fe[3:0], u8tmp1[1:0] => ea[7:6] */
420 /* u8tmp2[5:0] => ea[5:0] */
423 ret
= m88ds3103_rd_reg(priv
, 0xfe, &u8tmp
);
427 u8tmp
= ((u8tmp
& 0xf0) << 0) | u8tmp1
>> 2;
428 ret
= m88ds3103_wr_reg(priv
, 0xfe, u8tmp
);
432 u8tmp
= ((u8tmp1
& 0x03) << 6) | u8tmp2
>> 0;
433 ret
= m88ds3103_wr_reg(priv
, 0xea, u8tmp
);
437 switch (target_mclk
) {
439 u8tmp1
= 0x02; /* 0b10 */
440 u8tmp2
= 0x01; /* 0b01 */
443 u8tmp1
= 0x00; /* 0b00 */
444 u8tmp2
= 0x01; /* 0b01 */
447 u8tmp1
= 0x03; /* 0b11 */
448 u8tmp2
= 0x00; /* 0b00 */
452 ret
= m88ds3103_wr_reg_mask(priv
, 0x22, u8tmp1
<< 6, 0xc0);
456 ret
= m88ds3103_wr_reg_mask(priv
, 0x24, u8tmp2
<< 6, 0xc0);
460 if (c
->symbol_rate
<= 3000000)
462 else if (c
->symbol_rate
<= 10000000)
467 ret
= m88ds3103_wr_reg(priv
, 0xc3, 0x08);
471 ret
= m88ds3103_wr_reg(priv
, 0xc8, u8tmp
);
475 ret
= m88ds3103_wr_reg(priv
, 0xc4, 0x08);
479 ret
= m88ds3103_wr_reg(priv
, 0xc7, 0x00);
483 u16tmp
= DIV_ROUND_CLOSEST((c
->symbol_rate
/ 1000) << 15, M88DS3103_MCLK_KHZ
/ 2);
484 buf
[0] = (u16tmp
>> 0) & 0xff;
485 buf
[1] = (u16tmp
>> 8) & 0xff;
486 ret
= m88ds3103_wr_regs(priv
, 0x61, buf
, 2);
490 ret
= m88ds3103_wr_reg_mask(priv
, 0x4d, priv
->cfg
->spec_inv
<< 1, 0x02);
494 ret
= m88ds3103_wr_reg_mask(priv
, 0x30, priv
->cfg
->agc_inv
<< 4, 0x10);
498 ret
= m88ds3103_wr_reg(priv
, 0x33, priv
->cfg
->agc
);
502 dev_dbg(&priv
->i2c
->dev
, "%s: carrier offset=%d\n", __func__
,
503 (tuner_frequency
- c
->frequency
));
505 s32tmp
= 0x10000 * (tuner_frequency
- c
->frequency
);
506 s32tmp
= DIV_ROUND_CLOSEST(s32tmp
, M88DS3103_MCLK_KHZ
);
510 buf
[0] = (s32tmp
>> 0) & 0xff;
511 buf
[1] = (s32tmp
>> 8) & 0xff;
512 ret
= m88ds3103_wr_regs(priv
, 0x5e, buf
, 2);
516 ret
= m88ds3103_wr_reg(priv
, 0x00, 0x00);
520 ret
= m88ds3103_wr_reg(priv
, 0xb2, 0x00);
524 priv
->delivery_system
= c
->delivery_system
;
528 dev_dbg(&priv
->i2c
->dev
, "%s: failed=%d\n", __func__
, ret
);
532 static int m88ds3103_init(struct dvb_frontend
*fe
)
534 struct m88ds3103_priv
*priv
= fe
->demodulator_priv
;
535 int ret
, len
, remaining
;
536 const struct firmware
*fw
= NULL
;
537 u8
*fw_file
= M88DS3103_FIRMWARE
;
539 dev_dbg(&priv
->i2c
->dev
, "%s:\n", __func__
);
541 /* set cold state by default */
544 /* wake up device from sleep */
545 ret
= m88ds3103_wr_reg_mask(priv
, 0x08, 0x01, 0x01);
549 ret
= m88ds3103_wr_reg_mask(priv
, 0x04, 0x00, 0x01);
553 ret
= m88ds3103_wr_reg_mask(priv
, 0x23, 0x00, 0x10);
558 ret
= m88ds3103_wr_reg(priv
, 0x07, 0x60);
562 ret
= m88ds3103_wr_reg(priv
, 0x07, 0x00);
566 /* firmware status */
567 ret
= m88ds3103_rd_reg(priv
, 0xb9, &u8tmp
);
571 dev_dbg(&priv
->i2c
->dev
, "%s: firmware=%02x\n", __func__
, u8tmp
);
574 goto skip_fw_download
;
576 /* cold state - try to download firmware */
577 dev_info(&priv
->i2c
->dev
, "%s: found a '%s' in cold state\n",
578 KBUILD_MODNAME
, m88ds3103_ops
.info
.name
);
580 /* request the firmware, this will block and timeout */
581 ret
= request_firmware(&fw
, fw_file
, priv
->i2c
->dev
.parent
);
583 dev_err(&priv
->i2c
->dev
, "%s: firmare file '%s' not found\n",
584 KBUILD_MODNAME
, fw_file
);
588 dev_info(&priv
->i2c
->dev
, "%s: downloading firmware from file '%s'\n",
589 KBUILD_MODNAME
, fw_file
);
591 ret
= m88ds3103_wr_reg(priv
, 0xb2, 0x01);
595 for (remaining
= fw
->size
; remaining
> 0;
596 remaining
-= (priv
->cfg
->i2c_wr_max
- 1)) {
598 if (len
> (priv
->cfg
->i2c_wr_max
- 1))
599 len
= (priv
->cfg
->i2c_wr_max
- 1);
601 ret
= m88ds3103_wr_regs(priv
, 0xb0,
602 &fw
->data
[fw
->size
- remaining
], len
);
604 dev_err(&priv
->i2c
->dev
,
605 "%s: firmware download failed=%d\n",
606 KBUILD_MODNAME
, ret
);
611 ret
= m88ds3103_wr_reg(priv
, 0xb2, 0x00);
615 release_firmware(fw
);
618 ret
= m88ds3103_rd_reg(priv
, 0xb9, &u8tmp
);
623 dev_info(&priv
->i2c
->dev
, "%s: firmware did not run\n",
629 dev_info(&priv
->i2c
->dev
, "%s: found a '%s' in warm state\n",
630 KBUILD_MODNAME
, m88ds3103_ops
.info
.name
);
631 dev_info(&priv
->i2c
->dev
, "%s: firmware version %X.%X\n",
632 KBUILD_MODNAME
, (u8tmp
>> 4) & 0xf, (u8tmp
>> 0 & 0xf));
641 release_firmware(fw
);
643 dev_dbg(&priv
->i2c
->dev
, "%s: failed=%d\n", __func__
, ret
);
647 static int m88ds3103_sleep(struct dvb_frontend
*fe
)
649 struct m88ds3103_priv
*priv
= fe
->demodulator_priv
;
651 dev_dbg(&priv
->i2c
->dev
, "%s:\n", __func__
);
653 priv
->delivery_system
= SYS_UNDEFINED
;
656 ret
= m88ds3103_wr_reg_mask(priv
, 0x27, 0x00, 0x01);
661 ret
= m88ds3103_wr_reg_mask(priv
, 0x08, 0x00, 0x01);
665 ret
= m88ds3103_wr_reg_mask(priv
, 0x04, 0x01, 0x01);
669 ret
= m88ds3103_wr_reg_mask(priv
, 0x23, 0x10, 0x10);
675 dev_dbg(&priv
->i2c
->dev
, "%s: failed=%d\n", __func__
, ret
);
679 static int m88ds3103_get_frontend(struct dvb_frontend
*fe
)
681 struct m88ds3103_priv
*priv
= fe
->demodulator_priv
;
682 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
685 dev_dbg(&priv
->i2c
->dev
, "%s:\n", __func__
);
687 if (!priv
->warm
|| !(priv
->fe_status
& FE_HAS_LOCK
)) {
692 switch (c
->delivery_system
) {
694 ret
= m88ds3103_rd_reg(priv
, 0xe0, &buf
[0]);
698 ret
= m88ds3103_rd_reg(priv
, 0xe6, &buf
[1]);
702 switch ((buf
[0] >> 2) & 0x01) {
704 c
->inversion
= INVERSION_OFF
;
707 c
->inversion
= INVERSION_ON
;
711 switch ((buf
[1] >> 5) & 0x07) {
713 c
->fec_inner
= FEC_7_8
;
716 c
->fec_inner
= FEC_5_6
;
719 c
->fec_inner
= FEC_3_4
;
722 c
->fec_inner
= FEC_2_3
;
725 c
->fec_inner
= FEC_1_2
;
728 dev_dbg(&priv
->i2c
->dev
, "%s: invalid fec_inner\n",
732 c
->modulation
= QPSK
;
736 ret
= m88ds3103_rd_reg(priv
, 0x7e, &buf
[0]);
740 ret
= m88ds3103_rd_reg(priv
, 0x89, &buf
[1]);
744 ret
= m88ds3103_rd_reg(priv
, 0xf2, &buf
[2]);
748 switch ((buf
[0] >> 0) & 0x0f) {
750 c
->fec_inner
= FEC_2_5
;
753 c
->fec_inner
= FEC_1_2
;
756 c
->fec_inner
= FEC_3_5
;
759 c
->fec_inner
= FEC_2_3
;
762 c
->fec_inner
= FEC_3_4
;
765 c
->fec_inner
= FEC_4_5
;
768 c
->fec_inner
= FEC_5_6
;
771 c
->fec_inner
= FEC_8_9
;
774 c
->fec_inner
= FEC_9_10
;
777 dev_dbg(&priv
->i2c
->dev
, "%s: invalid fec_inner\n",
781 switch ((buf
[0] >> 5) & 0x01) {
783 c
->pilot
= PILOT_OFF
;
790 switch ((buf
[0] >> 6) & 0x07) {
792 c
->modulation
= QPSK
;
795 c
->modulation
= PSK_8
;
798 c
->modulation
= APSK_16
;
801 c
->modulation
= APSK_32
;
804 dev_dbg(&priv
->i2c
->dev
, "%s: invalid modulation\n",
808 switch ((buf
[1] >> 7) & 0x01) {
810 c
->inversion
= INVERSION_OFF
;
813 c
->inversion
= INVERSION_ON
;
817 switch ((buf
[2] >> 0) & 0x03) {
819 c
->rolloff
= ROLLOFF_35
;
822 c
->rolloff
= ROLLOFF_25
;
825 c
->rolloff
= ROLLOFF_20
;
828 dev_dbg(&priv
->i2c
->dev
, "%s: invalid rolloff\n",
833 dev_dbg(&priv
->i2c
->dev
, "%s: invalid delivery_system\n",
839 ret
= m88ds3103_rd_regs(priv
, 0x6d, buf
, 2);
843 c
->symbol_rate
= 1ull * ((buf
[1] << 8) | (buf
[0] << 0)) *
844 M88DS3103_MCLK_KHZ
* 1000 / 0x10000;
848 dev_dbg(&priv
->i2c
->dev
, "%s: failed=%d\n", __func__
, ret
);
852 static int m88ds3103_read_snr(struct dvb_frontend
*fe
, u16
*snr
)
854 struct m88ds3103_priv
*priv
= fe
->demodulator_priv
;
855 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
859 u32 noise_tot
, signal_tot
;
860 dev_dbg(&priv
->i2c
->dev
, "%s:\n", __func__
);
861 /* reports SNR in resolution of 0.1 dB */
863 /* more iterations for more accurate estimation */
864 #define M88DS3103_SNR_ITERATIONS 3
866 switch (c
->delivery_system
) {
870 for (i
= 0; i
< M88DS3103_SNR_ITERATIONS
; i
++) {
871 ret
= m88ds3103_rd_reg(priv
, 0xff, &buf
[0]);
878 /* use of one register limits max value to 15 dB */
879 /* SNR(X) dB = 10 * ln(X) / ln(10) dB */
880 tmp
= DIV_ROUND_CLOSEST(tmp
, 8 * M88DS3103_SNR_ITERATIONS
);
882 *snr
= 100ul * intlog2(tmp
) / intlog2(10);
890 for (i
= 0; i
< M88DS3103_SNR_ITERATIONS
; i
++) {
891 ret
= m88ds3103_rd_regs(priv
, 0x8c, buf
, 3);
895 noise
= buf
[1] << 6; /* [13:6] */
896 noise
|= buf
[0] & 0x3f; /* [5:0] */
898 signal
= buf
[2] * buf
[2];
902 signal_tot
+= signal
;
905 noise
= noise_tot
/ M88DS3103_SNR_ITERATIONS
;
906 signal
= signal_tot
/ M88DS3103_SNR_ITERATIONS
;
908 /* SNR(X) dB = 10 * log10(X) dB */
909 if (signal
> noise
) {
910 tmp
= signal
/ noise
;
911 *snr
= 100ul * intlog10(tmp
) / (1 << 24);
917 dev_dbg(&priv
->i2c
->dev
, "%s: invalid delivery_system\n",
925 dev_dbg(&priv
->i2c
->dev
, "%s: failed=%d\n", __func__
, ret
);
930 static int m88ds3103_set_tone(struct dvb_frontend
*fe
,
931 fe_sec_tone_mode_t fe_sec_tone_mode
)
933 struct m88ds3103_priv
*priv
= fe
->demodulator_priv
;
935 u8 u8tmp
, tone
, reg_a1_mask
;
936 dev_dbg(&priv
->i2c
->dev
, "%s: fe_sec_tone_mode=%d\n", __func__
,
944 switch (fe_sec_tone_mode
) {
954 dev_dbg(&priv
->i2c
->dev
, "%s: invalid fe_sec_tone_mode\n",
960 u8tmp
= tone
<< 7 | priv
->cfg
->envelope_mode
<< 5;
961 ret
= m88ds3103_wr_reg_mask(priv
, 0xa2, u8tmp
, 0xe0);
966 ret
= m88ds3103_wr_reg_mask(priv
, 0xa1, u8tmp
, reg_a1_mask
);
972 dev_dbg(&priv
->i2c
->dev
, "%s: failed=%d\n", __func__
, ret
);
976 static int m88ds3103_diseqc_send_master_cmd(struct dvb_frontend
*fe
,
977 struct dvb_diseqc_master_cmd
*diseqc_cmd
)
979 struct m88ds3103_priv
*priv
= fe
->demodulator_priv
;
982 dev_dbg(&priv
->i2c
->dev
, "%s: msg=%*ph\n", __func__
,
983 diseqc_cmd
->msg_len
, diseqc_cmd
->msg
);
990 if (diseqc_cmd
->msg_len
< 3 || diseqc_cmd
->msg_len
> 6) {
995 u8tmp
= priv
->cfg
->envelope_mode
<< 5;
996 ret
= m88ds3103_wr_reg_mask(priv
, 0xa2, u8tmp
, 0xe0);
1000 ret
= m88ds3103_wr_regs(priv
, 0xa3, diseqc_cmd
->msg
,
1001 diseqc_cmd
->msg_len
);
1005 ret
= m88ds3103_wr_reg(priv
, 0xa1,
1006 (diseqc_cmd
->msg_len
- 1) << 3 | 0x07);
1010 /* DiSEqC message typical period is 54 ms */
1011 usleep_range(40000, 60000);
1013 /* wait DiSEqC TX ready */
1014 for (i
= 20, u8tmp
= 1; i
&& u8tmp
; i
--) {
1015 usleep_range(5000, 10000);
1017 ret
= m88ds3103_rd_reg_mask(priv
, 0xa1, &u8tmp
, 0x40);
1022 dev_dbg(&priv
->i2c
->dev
, "%s: loop=%d\n", __func__
, i
);
1025 dev_dbg(&priv
->i2c
->dev
, "%s: diseqc tx timeout\n", __func__
);
1027 ret
= m88ds3103_wr_reg_mask(priv
, 0xa1, 0x40, 0xc0);
1032 ret
= m88ds3103_wr_reg_mask(priv
, 0xa2, 0x80, 0xc0);
1043 dev_dbg(&priv
->i2c
->dev
, "%s: failed=%d\n", __func__
, ret
);
1047 static int m88ds3103_diseqc_send_burst(struct dvb_frontend
*fe
,
1048 fe_sec_mini_cmd_t fe_sec_mini_cmd
)
1050 struct m88ds3103_priv
*priv
= fe
->demodulator_priv
;
1053 dev_dbg(&priv
->i2c
->dev
, "%s: fe_sec_mini_cmd=%d\n", __func__
,
1061 u8tmp
= priv
->cfg
->envelope_mode
<< 5;
1062 ret
= m88ds3103_wr_reg_mask(priv
, 0xa2, u8tmp
, 0xe0);
1066 switch (fe_sec_mini_cmd
) {
1074 dev_dbg(&priv
->i2c
->dev
, "%s: invalid fe_sec_mini_cmd\n",
1080 ret
= m88ds3103_wr_reg(priv
, 0xa1, burst
);
1084 /* DiSEqC ToneBurst period is 12.5 ms */
1085 usleep_range(11000, 20000);
1087 /* wait DiSEqC TX ready */
1088 for (i
= 5, u8tmp
= 1; i
&& u8tmp
; i
--) {
1089 usleep_range(800, 2000);
1091 ret
= m88ds3103_rd_reg_mask(priv
, 0xa1, &u8tmp
, 0x40);
1096 dev_dbg(&priv
->i2c
->dev
, "%s: loop=%d\n", __func__
, i
);
1098 ret
= m88ds3103_wr_reg_mask(priv
, 0xa2, 0x80, 0xc0);
1103 dev_dbg(&priv
->i2c
->dev
, "%s: diseqc tx timeout\n", __func__
);
1110 dev_dbg(&priv
->i2c
->dev
, "%s: failed=%d\n", __func__
, ret
);
1114 static int m88ds3103_get_tune_settings(struct dvb_frontend
*fe
,
1115 struct dvb_frontend_tune_settings
*s
)
1117 s
->min_delay_ms
= 3000;
1122 static void m88ds3103_release(struct dvb_frontend
*fe
)
1124 struct m88ds3103_priv
*priv
= fe
->demodulator_priv
;
1125 i2c_del_mux_adapter(priv
->i2c_adapter
);
1129 static int m88ds3103_select(struct i2c_adapter
*adap
, void *mux_priv
, u32 chan
)
1131 struct m88ds3103_priv
*priv
= mux_priv
;
1133 struct i2c_msg gate_open_msg
[1] = {
1135 .addr
= priv
->cfg
->i2c_addr
,
1142 mutex_lock(&priv
->i2c_mutex
);
1144 /* open tuner I2C repeater for 1 xfer, closes automatically */
1145 ret
= __i2c_transfer(priv
->i2c
, gate_open_msg
, 1);
1147 dev_warn(&priv
->i2c
->dev
, "%s: i2c wr failed=%d\n",
1148 KBUILD_MODNAME
, ret
);
1158 static int m88ds3103_deselect(struct i2c_adapter
*adap
, void *mux_priv
,
1161 struct m88ds3103_priv
*priv
= mux_priv
;
1163 mutex_unlock(&priv
->i2c_mutex
);
1168 struct dvb_frontend
*m88ds3103_attach(const struct m88ds3103_config
*cfg
,
1169 struct i2c_adapter
*i2c
, struct i2c_adapter
**tuner_i2c_adapter
)
1172 struct m88ds3103_priv
*priv
;
1175 /* allocate memory for the internal priv */
1176 priv
= kzalloc(sizeof(*priv
), GFP_KERNEL
);
1179 dev_err(&i2c
->dev
, "%s: kzalloc() failed\n", KBUILD_MODNAME
);
1185 mutex_init(&priv
->i2c_mutex
);
1187 ret
= m88ds3103_rd_reg(priv
, 0x01, &chip_id
);
1191 dev_dbg(&priv
->i2c
->dev
, "%s: chip_id=%02x\n", __func__
, chip_id
);
1200 switch (priv
->cfg
->clock_out
) {
1201 case M88DS3103_CLOCK_OUT_DISABLED
:
1204 case M88DS3103_CLOCK_OUT_ENABLED
:
1207 case M88DS3103_CLOCK_OUT_ENABLED_DIV2
:
1214 ret
= m88ds3103_wr_reg(priv
, 0x29, u8tmp
);
1219 ret
= m88ds3103_wr_reg_mask(priv
, 0x08, 0x00, 0x01);
1223 ret
= m88ds3103_wr_reg_mask(priv
, 0x04, 0x01, 0x01);
1227 ret
= m88ds3103_wr_reg_mask(priv
, 0x23, 0x10, 0x10);
1231 /* create mux i2c adapter for tuner */
1232 priv
->i2c_adapter
= i2c_add_mux_adapter(i2c
, &i2c
->dev
, priv
, 0, 0, 0,
1233 m88ds3103_select
, m88ds3103_deselect
);
1234 if (priv
->i2c_adapter
== NULL
)
1237 *tuner_i2c_adapter
= priv
->i2c_adapter
;
1239 /* create dvb_frontend */
1240 memcpy(&priv
->fe
.ops
, &m88ds3103_ops
, sizeof(struct dvb_frontend_ops
));
1241 priv
->fe
.demodulator_priv
= priv
;
1245 dev_dbg(&i2c
->dev
, "%s: failed=%d\n", __func__
, ret
);
1249 EXPORT_SYMBOL(m88ds3103_attach
);
1251 static struct dvb_frontend_ops m88ds3103_ops
= {
1252 .delsys
= { SYS_DVBS
, SYS_DVBS2
},
1254 .name
= "Montage M88DS3103",
1255 .frequency_min
= 950000,
1256 .frequency_max
= 2150000,
1257 .frequency_tolerance
= 5000,
1258 .symbol_rate_min
= 1000000,
1259 .symbol_rate_max
= 45000000,
1260 .caps
= FE_CAN_INVERSION_AUTO
|
1272 FE_CAN_2G_MODULATION
1275 .release
= m88ds3103_release
,
1277 .get_tune_settings
= m88ds3103_get_tune_settings
,
1279 .init
= m88ds3103_init
,
1280 .sleep
= m88ds3103_sleep
,
1282 .set_frontend
= m88ds3103_set_frontend
,
1283 .get_frontend
= m88ds3103_get_frontend
,
1285 .read_status
= m88ds3103_read_status
,
1286 .read_snr
= m88ds3103_read_snr
,
1288 .diseqc_send_master_cmd
= m88ds3103_diseqc_send_master_cmd
,
1289 .diseqc_send_burst
= m88ds3103_diseqc_send_burst
,
1291 .set_tone
= m88ds3103_set_tone
,
1294 MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
1295 MODULE_DESCRIPTION("Montage M88DS3103 DVB-S/S2 demodulator driver");
1296 MODULE_LICENSE("GPL");
1297 MODULE_FIRMWARE(M88DS3103_FIRMWARE
);