1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Montage Technology M88DS3103/M88RS6000 demodulator driver
5 * Copyright (C) 2013 Antti Palosaari <crope@iki.fi>
8 #include "m88ds3103_priv.h"
10 static const struct dvb_frontend_ops m88ds3103_ops
;
12 /* write single register with mask */
13 static int m88ds3103_update_bits(struct m88ds3103_dev
*dev
,
14 u8 reg
, u8 mask
, u8 val
)
19 /* no need for read if whole reg is written */
21 ret
= regmap_bulk_read(dev
->regmap
, reg
, &tmp
, 1);
30 return regmap_bulk_write(dev
->regmap
, reg
, &val
, 1);
33 /* write reg val table using reg addr auto increment */
34 static int m88ds3103_wr_reg_val_tab(struct m88ds3103_dev
*dev
,
35 const struct m88ds3103_reg_val
*tab
, int tab_len
)
37 struct i2c_client
*client
= dev
->client
;
41 dev_dbg(&client
->dev
, "tab_len=%d\n", tab_len
);
48 for (i
= 0, j
= 0; i
< tab_len
; i
++, j
++) {
51 if (i
== tab_len
- 1 || tab
[i
].reg
!= tab
[i
+ 1].reg
- 1 ||
52 !((j
+ 1) % (dev
->cfg
->i2c_wr_max
- 1))) {
53 ret
= regmap_bulk_write(dev
->regmap
, tab
[i
].reg
- j
, buf
, j
+ 1);
63 dev_dbg(&client
->dev
, "failed=%d\n", ret
);
68 * m88ds3103b demod has an internal device related to clocking. First the i2c
69 * gate must be opened, for one transaction, then writes will be allowed.
71 static int m88ds3103b_dt_write(struct m88ds3103_dev
*dev
, int reg
, int data
)
73 struct i2c_client
*client
= dev
->client
;
74 u8 buf
[] = {reg
, data
};
77 struct i2c_msg msg
= {
78 .addr
= dev
->dt_addr
, .flags
= 0, .buf
= buf
, .len
= 2
81 m88ds3103_update_bits(dev
, 0x11, 0x01, 0x00);
84 ret
= regmap_write(dev
->regmap
, 0x03, val
);
86 dev_dbg(&client
->dev
, "fail=%d\n", ret
);
88 ret
= i2c_transfer(dev
->dt_client
->adapter
, &msg
, 1);
90 dev_err(&client
->dev
, "0x%02x (ret=%i, reg=0x%02x, value=0x%02x)\n",
91 dev
->dt_addr
, ret
, reg
, data
);
93 m88ds3103_update_bits(dev
, 0x11, 0x01, 0x01);
96 m88ds3103_update_bits(dev
, 0x11, 0x01, 0x01);
98 dev_dbg(&client
->dev
, "0x%02x reg 0x%02x, value 0x%02x\n",
99 dev
->dt_addr
, reg
, data
);
105 * m88ds3103b demod has an internal device related to clocking. First the i2c
106 * gate must be opened, for two transactions, then reads will be allowed.
108 static int m88ds3103b_dt_read(struct m88ds3103_dev
*dev
, u8 reg
)
110 struct i2c_client
*client
= dev
->client
;
115 struct i2c_msg msg
[] = {
117 .addr
= dev
->dt_addr
,
123 .addr
= dev
->dt_addr
,
130 m88ds3103_update_bits(dev
, 0x11, 0x01, 0x00);
133 ret
= regmap_write(dev
->regmap
, 0x03, val
);
135 dev_dbg(&client
->dev
, "fail=%d\n", ret
);
137 ret
= i2c_transfer(dev
->dt_client
->adapter
, msg
, 2);
139 dev_err(&client
->dev
, "0x%02x (ret=%d, reg=0x%02x)\n",
140 dev
->dt_addr
, ret
, reg
);
142 m88ds3103_update_bits(dev
, 0x11, 0x01, 0x01);
145 m88ds3103_update_bits(dev
, 0x11, 0x01, 0x01);
147 dev_dbg(&client
->dev
, "0x%02x reg 0x%02x, value 0x%02x\n",
148 dev
->dt_addr
, reg
, b1
[0]);
154 * Get the demodulator AGC PWM voltage setting supplied to the tuner.
156 int m88ds3103_get_agc_pwm(struct dvb_frontend
*fe
, u8
*_agc_pwm
)
158 struct m88ds3103_dev
*dev
= fe
->demodulator_priv
;
162 ret
= regmap_read(dev
->regmap
, 0x3f, &tmp
);
167 EXPORT_SYMBOL(m88ds3103_get_agc_pwm
);
169 static int m88ds3103_read_status(struct dvb_frontend
*fe
,
170 enum fe_status
*status
)
172 struct m88ds3103_dev
*dev
= fe
->demodulator_priv
;
173 struct i2c_client
*client
= dev
->client
;
174 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
186 switch (c
->delivery_system
) {
188 ret
= regmap_read(dev
->regmap
, 0xd1, &utmp
);
192 if ((utmp
& 0x07) == 0x07)
193 *status
= FE_HAS_SIGNAL
| FE_HAS_CARRIER
|
194 FE_HAS_VITERBI
| FE_HAS_SYNC
|
198 ret
= regmap_read(dev
->regmap
, 0x0d, &utmp
);
202 if ((utmp
& 0x8f) == 0x8f)
203 *status
= FE_HAS_SIGNAL
| FE_HAS_CARRIER
|
204 FE_HAS_VITERBI
| FE_HAS_SYNC
|
208 dev_dbg(&client
->dev
, "invalid delivery_system\n");
213 dev
->fe_status
= *status
;
214 dev_dbg(&client
->dev
, "lock=%02x status=%02x\n", utmp
, *status
);
217 if (dev
->fe_status
& FE_HAS_VITERBI
) {
218 unsigned int cnr
, noise
, signal
, noise_tot
, signal_tot
;
221 /* more iterations for more accurate estimation */
222 #define M88DS3103_SNR_ITERATIONS 3
224 switch (c
->delivery_system
) {
228 for (i
= 0; i
< M88DS3103_SNR_ITERATIONS
; i
++) {
229 ret
= regmap_read(dev
->regmap
, 0xff, &utmp
);
236 /* use of single register limits max value to 15 dB */
237 /* SNR(X) dB = 10 * ln(X) / ln(10) dB */
238 itmp
= DIV_ROUND_CLOSEST(itmp
, 8 * M88DS3103_SNR_ITERATIONS
);
240 cnr
= div_u64((u64
) 10000 * intlog2(itmp
), intlog2(10));
246 for (i
= 0; i
< M88DS3103_SNR_ITERATIONS
; i
++) {
247 ret
= regmap_bulk_read(dev
->regmap
, 0x8c, buf
, 3);
251 noise
= buf
[1] << 6; /* [13:6] */
252 noise
|= buf
[0] & 0x3f; /* [5:0] */
254 signal
= buf
[2] * buf
[2];
258 signal_tot
+= signal
;
261 noise
= noise_tot
/ M88DS3103_SNR_ITERATIONS
;
262 signal
= signal_tot
/ M88DS3103_SNR_ITERATIONS
;
264 /* SNR(X) dB = 10 * log10(X) dB */
265 if (signal
> noise
) {
266 itmp
= signal
/ noise
;
267 cnr
= div_u64((u64
) 10000 * intlog10(itmp
), (1 << 24));
271 dev_dbg(&client
->dev
, "invalid delivery_system\n");
277 c
->cnr
.stat
[0].scale
= FE_SCALE_DECIBEL
;
278 c
->cnr
.stat
[0].svalue
= cnr
;
280 c
->cnr
.stat
[0].scale
= FE_SCALE_NOT_AVAILABLE
;
283 c
->cnr
.stat
[0].scale
= FE_SCALE_NOT_AVAILABLE
;
287 if (dev
->fe_status
& FE_HAS_LOCK
) {
288 unsigned int utmp
, post_bit_error
, post_bit_count
;
290 switch (c
->delivery_system
) {
292 ret
= regmap_write(dev
->regmap
, 0xf9, 0x04);
296 ret
= regmap_read(dev
->regmap
, 0xf8, &utmp
);
300 /* measurement ready? */
301 if (!(utmp
& 0x10)) {
302 ret
= regmap_bulk_read(dev
->regmap
, 0xf6, buf
, 2);
306 post_bit_error
= buf
[1] << 8 | buf
[0] << 0;
307 post_bit_count
= 0x800000;
308 dev
->post_bit_error
+= post_bit_error
;
309 dev
->post_bit_count
+= post_bit_count
;
310 dev
->dvbv3_ber
= post_bit_error
;
312 /* restart measurement */
314 ret
= regmap_write(dev
->regmap
, 0xf8, utmp
);
320 ret
= regmap_bulk_read(dev
->regmap
, 0xd5, buf
, 3);
324 utmp
= buf
[2] << 16 | buf
[1] << 8 | buf
[0] << 0;
328 ret
= regmap_bulk_read(dev
->regmap
, 0xf7, buf
, 2);
332 post_bit_error
= buf
[1] << 8 | buf
[0] << 0;
333 post_bit_count
= 32 * utmp
; /* TODO: FEC */
334 dev
->post_bit_error
+= post_bit_error
;
335 dev
->post_bit_count
+= post_bit_count
;
336 dev
->dvbv3_ber
= post_bit_error
;
338 /* restart measurement */
339 ret
= regmap_write(dev
->regmap
, 0xd1, 0x01);
343 ret
= regmap_write(dev
->regmap
, 0xf9, 0x01);
347 ret
= regmap_write(dev
->regmap
, 0xf9, 0x00);
351 ret
= regmap_write(dev
->regmap
, 0xd1, 0x00);
357 dev_dbg(&client
->dev
, "invalid delivery_system\n");
362 c
->post_bit_error
.stat
[0].scale
= FE_SCALE_COUNTER
;
363 c
->post_bit_error
.stat
[0].uvalue
= dev
->post_bit_error
;
364 c
->post_bit_count
.stat
[0].scale
= FE_SCALE_COUNTER
;
365 c
->post_bit_count
.stat
[0].uvalue
= dev
->post_bit_count
;
367 c
->post_bit_error
.stat
[0].scale
= FE_SCALE_NOT_AVAILABLE
;
368 c
->post_bit_count
.stat
[0].scale
= FE_SCALE_NOT_AVAILABLE
;
373 dev_dbg(&client
->dev
, "failed=%d\n", ret
);
377 static int m88ds3103b_select_mclk(struct m88ds3103_dev
*dev
)
379 struct i2c_client
*client
= dev
->client
;
380 struct dtv_frontend_properties
*c
= &dev
->fe
.dtv_property_cache
;
381 u32 adc_Freq_MHz
[3] = {96, 93, 99};
382 u8 reg16_list
[3] = {96, 92, 100}, reg16
, reg15
;
385 u32 old_setting
= dev
->mclk
;
386 u32 tuner_freq_MHz
= c
->frequency
/ 1000;
390 big_symbol
= (c
->symbol_rate
> 45010000) ? 1 : 0;
397 /* TODO: IS THIS NECESSARY ? */
398 for (i
= 0; i
< 3; i
++) {
399 offset_MHz
[i
] = tuner_freq_MHz
% adc_Freq_MHz
[i
];
401 if (offset_MHz
[i
] > (adc_Freq_MHz
[i
] / 2))
402 offset_MHz
[i
] = adc_Freq_MHz
[i
] - offset_MHz
[i
];
404 if (offset_MHz
[i
] > max_offset
) {
405 max_offset
= offset_MHz
[i
];
406 reg16
= reg16_list
[i
];
407 dev
->mclk
= adc_Freq_MHz
[i
] * 1000 * 1000;
412 dev_dbg(&client
->dev
, "modifying mclk %u -> %u\n",
413 old_setting
, dev
->mclk
);
418 if (dev
->mclk
== 93000000)
419 regmap_write(dev
->regmap
, 0xA0, 0x42);
420 else if (dev
->mclk
== 96000000)
421 regmap_write(dev
->regmap
, 0xA0, 0x44);
422 else if (dev
->mclk
== 99000000)
423 regmap_write(dev
->regmap
, 0xA0, 0x46);
424 else if (dev
->mclk
== 110250000)
425 regmap_write(dev
->regmap
, 0xA0, 0x4E);
427 regmap_write(dev
->regmap
, 0xA0, 0x44);
429 reg15
= m88ds3103b_dt_read(dev
, 0x15);
431 m88ds3103b_dt_write(dev
, 0x05, 0x40);
432 m88ds3103b_dt_write(dev
, 0x11, 0x08);
439 m88ds3103b_dt_write(dev
, 0x15, reg15
);
440 m88ds3103b_dt_write(dev
, 0x16, reg16
);
442 usleep_range(5000, 5500);
444 m88ds3103b_dt_write(dev
, 0x05, 0x00);
445 m88ds3103b_dt_write(dev
, 0x11, (u8
)(big_symbol
? 0x0E : 0x0A));
447 usleep_range(5000, 5500);
452 static int m88ds3103b_set_mclk(struct m88ds3103_dev
*dev
, u32 mclk_khz
)
454 u8 reg11
= 0x0A, reg15
, reg16
, reg1D
, reg1E
, reg1F
, tmp
;
455 u8 sm
, f0
= 0, f1
= 0, f2
= 0, f3
= 0;
459 reg15
= m88ds3103b_dt_read(dev
, 0x15);
460 reg16
= m88ds3103b_dt_read(dev
, 0x16);
461 reg1D
= m88ds3103b_dt_read(dev
, 0x1D);
463 if (dev
->cfg
->ts_mode
!= M88DS3103_TS_SERIAL
) {
466 else if (reg16
== 100)
475 pll_div_fb
= (reg15
& 0x01) << 8;
479 div
= 9000 * pll_div_fb
* 4;
482 if (dev
->cfg
->ts_mode
== M88DS3103_TS_SERIAL
) {
492 } else if (div
<= 34) {
496 f1
= (div
- f0
) / (N
- 1);
499 } else if (div
<= 64) {
503 f1
= (div
- f0
) / (N
- 1);
504 f2
= (div
- f0
- f1
) / (N
- 2);
505 f3
= div
- f0
- f1
- f2
;
517 else if ((f0
< 8) && (f0
!= 0))
522 else if ((f1
< 8) && (f1
!= 0))
527 else if ((f2
< 8) && (f2
!= 0))
532 else if ((f3
< 8) && (f3
!= 0))
544 } else if (div
<= 48) {
548 f1
= (div
- f0
) / (N
- 1);
551 } else if (div
<= 64) {
555 f1
= (div
- f0
) / (N
- 1);
556 f2
= (div
- f0
- f1
) / (N
- 2);
557 f3
= div
- f0
- f1
- f2
;
569 else if ((f0
< 9) && (f0
!= 0))
574 else if ((f1
< 9) && (f1
!= 0))
579 else if ((f2
< 9) && (f2
!= 0))
584 else if ((f3
< 9) && (f3
!= 0))
590 /* Write to registers */
592 //reg15 |= (pll_div_fb >> 8) & 0x01;
594 //reg16 = pll_div_fb & 0xFF;
600 reg1E
= ((f3
<< 4) + f2
) & 0xFF;
601 reg1F
= ((f1
<< 4) + f0
) & 0xFF;
603 m88ds3103b_dt_write(dev
, 0x05, 0x40);
604 m88ds3103b_dt_write(dev
, 0x11, 0x08);
605 m88ds3103b_dt_write(dev
, 0x1D, reg1D
);
606 m88ds3103b_dt_write(dev
, 0x1E, reg1E
);
607 m88ds3103b_dt_write(dev
, 0x1F, reg1F
);
609 m88ds3103b_dt_write(dev
, 0x17, 0xc1);
610 m88ds3103b_dt_write(dev
, 0x17, 0x81);
612 usleep_range(5000, 5500);
614 m88ds3103b_dt_write(dev
, 0x05, 0x00);
615 m88ds3103b_dt_write(dev
, 0x11, 0x0A);
617 usleep_range(5000, 5500);
622 static int m88ds3103_set_frontend(struct dvb_frontend
*fe
)
624 struct m88ds3103_dev
*dev
= fe
->demodulator_priv
;
625 struct i2c_client
*client
= dev
->client
;
626 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
628 const struct m88ds3103_reg_val
*init
;
629 u8 u8tmp
, u8tmp1
= 0, u8tmp2
= 0; /* silence compiler warning */
632 u32 tuner_frequency_khz
, target_mclk
, u32tmp
;
634 static const struct reg_sequence reset_buf
[] = {
635 {0x07, 0x80}, {0x07, 0x00}
638 dev_dbg(&client
->dev
,
639 "delivery_system=%d modulation=%d frequency=%u symbol_rate=%d inversion=%d pilot=%d rolloff=%d\n",
640 c
->delivery_system
, c
->modulation
, c
->frequency
, c
->symbol_rate
,
641 c
->inversion
, c
->pilot
, c
->rolloff
);
649 ret
= regmap_multi_reg_write(dev
->regmap
, reset_buf
, 2);
653 /* Disable demod clock path */
654 if (dev
->chip_id
== M88RS6000_CHIP_ID
) {
655 if (dev
->chiptype
== M88DS3103_CHIPTYPE_3103B
) {
656 ret
= regmap_read(dev
->regmap
, 0xb2, &u32tmp
);
659 if (u32tmp
== 0x01) {
660 ret
= regmap_write(dev
->regmap
, 0x00, 0x00);
663 ret
= regmap_write(dev
->regmap
, 0xb2, 0x00);
669 ret
= regmap_write(dev
->regmap
, 0x06, 0xe0);
675 if (fe
->ops
.tuner_ops
.set_params
) {
676 ret
= fe
->ops
.tuner_ops
.set_params(fe
);
681 if (fe
->ops
.tuner_ops
.get_frequency
) {
682 ret
= fe
->ops
.tuner_ops
.get_frequency(fe
, &tuner_frequency_khz
);
687 * Use nominal target frequency as tuner driver does not provide
688 * actual frequency used. Carrier offset calculation is not
691 tuner_frequency_khz
= c
->frequency
;
694 /* set M88RS6000/DS3103B demod main mclk and ts mclk from tuner die */
695 if (dev
->chip_id
== M88RS6000_CHIP_ID
) {
696 if (c
->symbol_rate
> 45010000)
697 dev
->mclk
= 110250000;
699 dev
->mclk
= 96000000;
701 if (c
->delivery_system
== SYS_DVBS
)
702 target_mclk
= 96000000;
704 target_mclk
= 144000000;
706 if (dev
->chiptype
== M88DS3103_CHIPTYPE_3103B
) {
707 m88ds3103b_select_mclk(dev
);
708 m88ds3103b_set_mclk(dev
, target_mclk
/ 1000);
711 /* Enable demod clock path */
712 ret
= regmap_write(dev
->regmap
, 0x06, 0x00);
715 usleep_range(10000, 20000);
717 /* set M88DS3103 mclk and ts mclk. */
718 dev
->mclk
= 96000000;
720 switch (dev
->cfg
->ts_mode
) {
721 case M88DS3103_TS_SERIAL
:
722 case M88DS3103_TS_SERIAL_D7
:
723 target_mclk
= dev
->cfg
->ts_clk
;
725 case M88DS3103_TS_PARALLEL
:
726 case M88DS3103_TS_CI
:
727 if (c
->delivery_system
== SYS_DVBS
)
728 target_mclk
= 96000000;
730 if (c
->symbol_rate
< 18000000)
731 target_mclk
= 96000000;
732 else if (c
->symbol_rate
< 28000000)
733 target_mclk
= 144000000;
735 target_mclk
= 192000000;
739 dev_dbg(&client
->dev
, "invalid ts_mode\n");
744 switch (target_mclk
) {
746 u8tmp1
= 0x02; /* 0b10 */
747 u8tmp2
= 0x01; /* 0b01 */
750 u8tmp1
= 0x00; /* 0b00 */
751 u8tmp2
= 0x01; /* 0b01 */
754 u8tmp1
= 0x03; /* 0b11 */
755 u8tmp2
= 0x00; /* 0b00 */
758 ret
= m88ds3103_update_bits(dev
, 0x22, 0xc0, u8tmp1
<< 6);
761 ret
= m88ds3103_update_bits(dev
, 0x24, 0xc0, u8tmp2
<< 6);
766 ret
= regmap_write(dev
->regmap
, 0xb2, 0x01);
770 ret
= regmap_write(dev
->regmap
, 0x00, 0x01);
774 switch (c
->delivery_system
) {
776 if (dev
->chip_id
== M88RS6000_CHIP_ID
) {
777 len
= ARRAY_SIZE(m88rs6000_dvbs_init_reg_vals
);
778 init
= m88rs6000_dvbs_init_reg_vals
;
780 len
= ARRAY_SIZE(m88ds3103_dvbs_init_reg_vals
);
781 init
= m88ds3103_dvbs_init_reg_vals
;
785 if (dev
->chip_id
== M88RS6000_CHIP_ID
) {
786 len
= ARRAY_SIZE(m88rs6000_dvbs2_init_reg_vals
);
787 init
= m88rs6000_dvbs2_init_reg_vals
;
789 len
= ARRAY_SIZE(m88ds3103_dvbs2_init_reg_vals
);
790 init
= m88ds3103_dvbs2_init_reg_vals
;
794 dev_dbg(&client
->dev
, "invalid delivery_system\n");
799 /* program init table */
800 if (c
->delivery_system
!= dev
->delivery_system
) {
801 ret
= m88ds3103_wr_reg_val_tab(dev
, init
, len
);
806 if (dev
->chip_id
== M88RS6000_CHIP_ID
) {
807 if (c
->delivery_system
== SYS_DVBS2
&&
808 c
->symbol_rate
<= 5000000) {
809 ret
= regmap_write(dev
->regmap
, 0xc0, 0x04);
815 ret
= regmap_bulk_write(dev
->regmap
, 0x8a, buf
, 3);
819 ret
= m88ds3103_update_bits(dev
, 0x9d, 0x08, 0x08);
823 if (dev
->chiptype
== M88DS3103_CHIPTYPE_3103B
) {
824 buf
[0] = m88ds3103b_dt_read(dev
, 0x15);
825 buf
[1] = m88ds3103b_dt_read(dev
, 0x16);
827 if (c
->symbol_rate
> 45010000) {
830 buf
[0] |= ((147 - 32) >> 8) & 0x01;
831 buf
[1] = (147 - 32) & 0xFF;
833 dev
->mclk
= 110250 * 1000;
836 buf
[0] |= ((128 - 32) >> 8) & 0x01;
837 buf
[1] = (128 - 32) & 0xFF;
839 dev
->mclk
= 96000 * 1000;
841 m88ds3103b_dt_write(dev
, 0x15, buf
[0]);
842 m88ds3103b_dt_write(dev
, 0x16, buf
[1]);
844 regmap_read(dev
->regmap
, 0x30, &u32tmp
);
846 regmap_write(dev
->regmap
, 0x30, u32tmp
& 0xff);
849 ret
= regmap_write(dev
->regmap
, 0xf1, 0x01);
853 if (dev
->chiptype
!= M88DS3103_CHIPTYPE_3103B
) {
854 ret
= m88ds3103_update_bits(dev
, 0x30, 0x80, 0x80);
860 switch (dev
->cfg
->ts_mode
) {
861 case M88DS3103_TS_SERIAL
:
865 case M88DS3103_TS_SERIAL_D7
:
869 case M88DS3103_TS_PARALLEL
:
871 if (dev
->chiptype
== M88DS3103_CHIPTYPE_3103B
) {
876 case M88DS3103_TS_CI
:
880 dev_dbg(&client
->dev
, "invalid ts_mode\n");
885 if (dev
->cfg
->ts_clk_pol
)
889 ret
= regmap_write(dev
->regmap
, 0xfd, u8tmp
);
893 switch (dev
->cfg
->ts_mode
) {
894 case M88DS3103_TS_SERIAL
:
895 case M88DS3103_TS_SERIAL_D7
:
896 ret
= m88ds3103_update_bits(dev
, 0x29, 0x20, u8tmp1
);
903 case M88DS3103_TS_PARALLEL
:
904 if (dev
->chiptype
== M88DS3103_CHIPTYPE_3103B
) {
905 ret
= m88ds3103_update_bits(dev
, 0x29, 0x01, u8tmp1
);
911 u16tmp
= DIV_ROUND_UP(target_mclk
, dev
->cfg
->ts_clk
);
912 u8tmp1
= u16tmp
/ 2 - 1;
913 u8tmp2
= DIV_ROUND_UP(u16tmp
, 2) - 1;
916 dev_dbg(&client
->dev
, "target_mclk=%u ts_clk=%u ts_clk_divide_ratio=%u\n",
917 target_mclk
, dev
->cfg
->ts_clk
, u16tmp
);
919 /* u8tmp1[5:2] => fe[3:0], u8tmp1[1:0] => ea[7:6] */
920 /* u8tmp2[5:0] => ea[5:0] */
921 u8tmp
= (u8tmp1
>> 2) & 0x0f;
922 ret
= regmap_update_bits(dev
->regmap
, 0xfe, 0x0f, u8tmp
);
925 u8tmp
= ((u8tmp1
& 0x03) << 6) | u8tmp2
>> 0;
926 ret
= regmap_write(dev
->regmap
, 0xea, u8tmp
);
930 if (c
->symbol_rate
<= 3000000)
932 else if (c
->symbol_rate
<= 10000000)
937 if (dev
->chiptype
== M88DS3103_CHIPTYPE_3103B
)
938 m88ds3103b_set_mclk(dev
, target_mclk
/ 1000);
940 ret
= regmap_write(dev
->regmap
, 0xc3, 0x08);
944 ret
= regmap_write(dev
->regmap
, 0xc8, u8tmp
);
948 ret
= regmap_write(dev
->regmap
, 0xc4, 0x08);
952 ret
= regmap_write(dev
->regmap
, 0xc7, 0x00);
956 u16tmp
= DIV_ROUND_CLOSEST_ULL((u64
)c
->symbol_rate
* 0x10000, dev
->mclk
);
957 buf
[0] = (u16tmp
>> 0) & 0xff;
958 buf
[1] = (u16tmp
>> 8) & 0xff;
959 ret
= regmap_bulk_write(dev
->regmap
, 0x61, buf
, 2);
963 ret
= m88ds3103_update_bits(dev
, 0x4d, 0x02, dev
->cfg
->spec_inv
<< 1);
967 ret
= m88ds3103_update_bits(dev
, 0x30, 0x10, dev
->cfg
->agc_inv
<< 4);
971 ret
= regmap_write(dev
->regmap
, 0x33, dev
->cfg
->agc
);
975 if (dev
->chiptype
== M88DS3103_CHIPTYPE_3103B
) {
976 /* enable/disable 192M LDPC clock */
977 ret
= m88ds3103_update_bits(dev
, 0x29, 0x10,
978 (c
->delivery_system
== SYS_DVBS
) ? 0x10 : 0x0);
982 ret
= m88ds3103_update_bits(dev
, 0xc9, 0x08, 0x08);
987 dev_dbg(&client
->dev
, "carrier offset=%d\n",
988 (tuner_frequency_khz
- c
->frequency
));
990 /* Use 32-bit calc as there is no s64 version of DIV_ROUND_CLOSEST() */
991 s32tmp
= 0x10000 * (tuner_frequency_khz
- c
->frequency
);
992 s32tmp
= DIV_ROUND_CLOSEST(s32tmp
, dev
->mclk
/ 1000);
993 buf
[0] = (s32tmp
>> 0) & 0xff;
994 buf
[1] = (s32tmp
>> 8) & 0xff;
995 ret
= regmap_bulk_write(dev
->regmap
, 0x5e, buf
, 2);
999 ret
= regmap_write(dev
->regmap
, 0x00, 0x00);
1003 ret
= regmap_write(dev
->regmap
, 0xb2, 0x00);
1007 dev
->delivery_system
= c
->delivery_system
;
1011 dev_dbg(&client
->dev
, "failed=%d\n", ret
);
1015 static int m88ds3103_init(struct dvb_frontend
*fe
)
1017 struct m88ds3103_dev
*dev
= fe
->demodulator_priv
;
1018 struct i2c_client
*client
= dev
->client
;
1019 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
1022 const struct firmware
*firmware
;
1025 dev_dbg(&client
->dev
, "\n");
1027 /* set cold state by default */
1030 /* wake up device from sleep */
1031 ret
= m88ds3103_update_bits(dev
, 0x08, 0x01, 0x01);
1034 ret
= m88ds3103_update_bits(dev
, 0x04, 0x01, 0x00);
1037 ret
= m88ds3103_update_bits(dev
, 0x23, 0x10, 0x00);
1041 /* firmware status */
1042 ret
= regmap_read(dev
->regmap
, 0xb9, &utmp
);
1046 dev_dbg(&client
->dev
, "firmware=%02x\n", utmp
);
1051 /* global reset, global diseqc reset, global fec reset */
1052 ret
= regmap_write(dev
->regmap
, 0x07, 0xe0);
1055 ret
= regmap_write(dev
->regmap
, 0x07, 0x00);
1059 /* cold state - try to download firmware */
1060 dev_info(&client
->dev
, "found a '%s' in cold state\n",
1061 dev
->fe
.ops
.info
.name
);
1063 if (dev
->chiptype
== M88DS3103_CHIPTYPE_3103B
)
1064 name
= M88DS3103B_FIRMWARE
;
1065 else if (dev
->chip_id
== M88RS6000_CHIP_ID
)
1066 name
= M88RS6000_FIRMWARE
;
1068 name
= M88DS3103_FIRMWARE
;
1070 /* request the firmware, this will block and timeout */
1071 ret
= request_firmware(&firmware
, name
, &client
->dev
);
1073 dev_err(&client
->dev
, "firmware file '%s' not found\n", name
);
1077 dev_info(&client
->dev
, "downloading firmware from file '%s'\n", name
);
1079 ret
= regmap_write(dev
->regmap
, 0xb2, 0x01);
1081 goto err_release_firmware
;
1083 for (rem
= firmware
->size
; rem
> 0; rem
-= (dev
->cfg
->i2c_wr_max
- 1)) {
1084 len
= min(dev
->cfg
->i2c_wr_max
- 1, rem
);
1085 ret
= regmap_bulk_write(dev
->regmap
, 0xb0,
1086 &firmware
->data
[firmware
->size
- rem
],
1089 dev_err(&client
->dev
, "firmware download failed %d\n",
1091 goto err_release_firmware
;
1095 ret
= regmap_write(dev
->regmap
, 0xb2, 0x00);
1097 goto err_release_firmware
;
1099 release_firmware(firmware
);
1101 ret
= regmap_read(dev
->regmap
, 0xb9, &utmp
);
1107 dev_info(&client
->dev
, "firmware did not run\n");
1111 dev_info(&client
->dev
, "found a '%s' in warm state\n",
1112 dev
->fe
.ops
.info
.name
);
1113 dev_info(&client
->dev
, "firmware version: %X.%X\n",
1114 (utmp
>> 4) & 0xf, (utmp
>> 0 & 0xf));
1116 if (dev
->chiptype
== M88DS3103_CHIPTYPE_3103B
) {
1117 m88ds3103b_dt_write(dev
, 0x21, 0x92);
1118 m88ds3103b_dt_write(dev
, 0x15, 0x6C);
1119 m88ds3103b_dt_write(dev
, 0x17, 0xC1);
1120 m88ds3103b_dt_write(dev
, 0x17, 0x81);
1126 /* init stats here in order signal app which stats are supported */
1128 c
->cnr
.stat
[0].scale
= FE_SCALE_NOT_AVAILABLE
;
1129 c
->post_bit_error
.len
= 1;
1130 c
->post_bit_error
.stat
[0].scale
= FE_SCALE_NOT_AVAILABLE
;
1131 c
->post_bit_count
.len
= 1;
1132 c
->post_bit_count
.stat
[0].scale
= FE_SCALE_NOT_AVAILABLE
;
1135 err_release_firmware
:
1136 release_firmware(firmware
);
1138 dev_dbg(&client
->dev
, "failed=%d\n", ret
);
1142 static int m88ds3103_sleep(struct dvb_frontend
*fe
)
1144 struct m88ds3103_dev
*dev
= fe
->demodulator_priv
;
1145 struct i2c_client
*client
= dev
->client
;
1149 dev_dbg(&client
->dev
, "\n");
1152 dev
->delivery_system
= SYS_UNDEFINED
;
1155 if (dev
->chip_id
== M88RS6000_CHIP_ID
)
1159 ret
= m88ds3103_update_bits(dev
, utmp
, 0x01, 0x00);
1164 ret
= m88ds3103_update_bits(dev
, 0x08, 0x01, 0x00);
1167 ret
= m88ds3103_update_bits(dev
, 0x04, 0x01, 0x01);
1170 ret
= m88ds3103_update_bits(dev
, 0x23, 0x10, 0x10);
1176 dev_dbg(&client
->dev
, "failed=%d\n", ret
);
1180 static int m88ds3103_get_frontend(struct dvb_frontend
*fe
,
1181 struct dtv_frontend_properties
*c
)
1183 struct m88ds3103_dev
*dev
= fe
->demodulator_priv
;
1184 struct i2c_client
*client
= dev
->client
;
1188 dev_dbg(&client
->dev
, "\n");
1190 if (!dev
->warm
|| !(dev
->fe_status
& FE_HAS_LOCK
)) {
1195 switch (c
->delivery_system
) {
1197 ret
= regmap_bulk_read(dev
->regmap
, 0xe0, &buf
[0], 1);
1201 ret
= regmap_bulk_read(dev
->regmap
, 0xe6, &buf
[1], 1);
1205 switch ((buf
[0] >> 2) & 0x01) {
1207 c
->inversion
= INVERSION_OFF
;
1210 c
->inversion
= INVERSION_ON
;
1214 switch ((buf
[1] >> 5) & 0x07) {
1216 c
->fec_inner
= FEC_7_8
;
1219 c
->fec_inner
= FEC_5_6
;
1222 c
->fec_inner
= FEC_3_4
;
1225 c
->fec_inner
= FEC_2_3
;
1228 c
->fec_inner
= FEC_1_2
;
1231 dev_dbg(&client
->dev
, "invalid fec_inner\n");
1234 c
->modulation
= QPSK
;
1238 ret
= regmap_bulk_read(dev
->regmap
, 0x7e, &buf
[0], 1);
1242 ret
= regmap_bulk_read(dev
->regmap
, 0x89, &buf
[1], 1);
1246 ret
= regmap_bulk_read(dev
->regmap
, 0xf2, &buf
[2], 1);
1250 switch ((buf
[0] >> 0) & 0x0f) {
1252 c
->fec_inner
= FEC_2_5
;
1255 c
->fec_inner
= FEC_1_2
;
1258 c
->fec_inner
= FEC_3_5
;
1261 c
->fec_inner
= FEC_2_3
;
1264 c
->fec_inner
= FEC_3_4
;
1267 c
->fec_inner
= FEC_4_5
;
1270 c
->fec_inner
= FEC_5_6
;
1273 c
->fec_inner
= FEC_8_9
;
1276 c
->fec_inner
= FEC_9_10
;
1279 dev_dbg(&client
->dev
, "invalid fec_inner\n");
1282 switch ((buf
[0] >> 5) & 0x01) {
1284 c
->pilot
= PILOT_OFF
;
1287 c
->pilot
= PILOT_ON
;
1291 switch ((buf
[0] >> 6) & 0x07) {
1293 c
->modulation
= QPSK
;
1296 c
->modulation
= PSK_8
;
1299 c
->modulation
= APSK_16
;
1302 c
->modulation
= APSK_32
;
1305 dev_dbg(&client
->dev
, "invalid modulation\n");
1308 switch ((buf
[1] >> 7) & 0x01) {
1310 c
->inversion
= INVERSION_OFF
;
1313 c
->inversion
= INVERSION_ON
;
1317 switch ((buf
[2] >> 0) & 0x03) {
1319 c
->rolloff
= ROLLOFF_35
;
1322 c
->rolloff
= ROLLOFF_25
;
1325 c
->rolloff
= ROLLOFF_20
;
1328 dev_dbg(&client
->dev
, "invalid rolloff\n");
1332 dev_dbg(&client
->dev
, "invalid delivery_system\n");
1337 ret
= regmap_bulk_read(dev
->regmap
, 0x6d, buf
, 2);
1341 c
->symbol_rate
= DIV_ROUND_CLOSEST_ULL((u64
)(buf
[1] << 8 | buf
[0] << 0) * dev
->mclk
, 0x10000);
1345 dev_dbg(&client
->dev
, "failed=%d\n", ret
);
1349 static int m88ds3103_read_snr(struct dvb_frontend
*fe
, u16
*snr
)
1351 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
1353 if (c
->cnr
.stat
[0].scale
== FE_SCALE_DECIBEL
)
1354 *snr
= div_s64(c
->cnr
.stat
[0].svalue
, 100);
1361 static int m88ds3103_read_ber(struct dvb_frontend
*fe
, u32
*ber
)
1363 struct m88ds3103_dev
*dev
= fe
->demodulator_priv
;
1365 *ber
= dev
->dvbv3_ber
;
1370 static int m88ds3103_set_tone(struct dvb_frontend
*fe
,
1371 enum fe_sec_tone_mode fe_sec_tone_mode
)
1373 struct m88ds3103_dev
*dev
= fe
->demodulator_priv
;
1374 struct i2c_client
*client
= dev
->client
;
1376 unsigned int utmp
, tone
, reg_a1_mask
;
1378 dev_dbg(&client
->dev
, "fe_sec_tone_mode=%d\n", fe_sec_tone_mode
);
1385 switch (fe_sec_tone_mode
) {
1395 dev_dbg(&client
->dev
, "invalid fe_sec_tone_mode\n");
1400 utmp
= tone
<< 7 | dev
->cfg
->envelope_mode
<< 5;
1401 ret
= m88ds3103_update_bits(dev
, 0xa2, 0xe0, utmp
);
1406 ret
= m88ds3103_update_bits(dev
, 0xa1, reg_a1_mask
, utmp
);
1412 dev_dbg(&client
->dev
, "failed=%d\n", ret
);
1416 static int m88ds3103_set_voltage(struct dvb_frontend
*fe
,
1417 enum fe_sec_voltage fe_sec_voltage
)
1419 struct m88ds3103_dev
*dev
= fe
->demodulator_priv
;
1420 struct i2c_client
*client
= dev
->client
;
1423 bool voltage_sel
, voltage_dis
;
1425 dev_dbg(&client
->dev
, "fe_sec_voltage=%d\n", fe_sec_voltage
);
1432 switch (fe_sec_voltage
) {
1433 case SEC_VOLTAGE_18
:
1435 voltage_dis
= false;
1437 case SEC_VOLTAGE_13
:
1438 voltage_sel
= false;
1439 voltage_dis
= false;
1441 case SEC_VOLTAGE_OFF
:
1442 voltage_sel
= false;
1446 dev_dbg(&client
->dev
, "invalid fe_sec_voltage\n");
1451 /* output pin polarity */
1452 voltage_sel
^= dev
->cfg
->lnb_hv_pol
;
1453 voltage_dis
^= dev
->cfg
->lnb_en_pol
;
1455 utmp
= voltage_dis
<< 1 | voltage_sel
<< 0;
1456 ret
= m88ds3103_update_bits(dev
, 0xa2, 0x03, utmp
);
1462 dev_dbg(&client
->dev
, "failed=%d\n", ret
);
1466 static int m88ds3103_diseqc_send_master_cmd(struct dvb_frontend
*fe
,
1467 struct dvb_diseqc_master_cmd
*diseqc_cmd
)
1469 struct m88ds3103_dev
*dev
= fe
->demodulator_priv
;
1470 struct i2c_client
*client
= dev
->client
;
1473 unsigned long timeout
;
1475 dev_dbg(&client
->dev
, "msg=%*ph\n",
1476 diseqc_cmd
->msg_len
, diseqc_cmd
->msg
);
1483 if (diseqc_cmd
->msg_len
< 3 || diseqc_cmd
->msg_len
> 6) {
1488 utmp
= dev
->cfg
->envelope_mode
<< 5;
1489 ret
= m88ds3103_update_bits(dev
, 0xa2, 0xe0, utmp
);
1493 ret
= regmap_bulk_write(dev
->regmap
, 0xa3, diseqc_cmd
->msg
,
1494 diseqc_cmd
->msg_len
);
1498 ret
= regmap_write(dev
->regmap
, 0xa1,
1499 (diseqc_cmd
->msg_len
- 1) << 3 | 0x07);
1503 /* wait DiSEqC TX ready */
1504 #define SEND_MASTER_CMD_TIMEOUT 120
1505 timeout
= jiffies
+ msecs_to_jiffies(SEND_MASTER_CMD_TIMEOUT
);
1507 /* DiSEqC message period is 13.5 ms per byte */
1508 utmp
= diseqc_cmd
->msg_len
* 13500;
1509 usleep_range(utmp
- 4000, utmp
);
1511 for (utmp
= 1; !time_after(jiffies
, timeout
) && utmp
;) {
1512 ret
= regmap_read(dev
->regmap
, 0xa1, &utmp
);
1515 utmp
= (utmp
>> 6) & 0x1;
1519 dev_dbg(&client
->dev
, "diseqc tx took %u ms\n",
1520 jiffies_to_msecs(jiffies
) -
1521 (jiffies_to_msecs(timeout
) - SEND_MASTER_CMD_TIMEOUT
));
1523 dev_dbg(&client
->dev
, "diseqc tx timeout\n");
1525 ret
= m88ds3103_update_bits(dev
, 0xa1, 0xc0, 0x40);
1530 ret
= m88ds3103_update_bits(dev
, 0xa2, 0xc0, 0x80);
1541 dev_dbg(&client
->dev
, "failed=%d\n", ret
);
1545 static int m88ds3103_diseqc_send_burst(struct dvb_frontend
*fe
,
1546 enum fe_sec_mini_cmd fe_sec_mini_cmd
)
1548 struct m88ds3103_dev
*dev
= fe
->demodulator_priv
;
1549 struct i2c_client
*client
= dev
->client
;
1551 unsigned int utmp
, burst
;
1552 unsigned long timeout
;
1554 dev_dbg(&client
->dev
, "fe_sec_mini_cmd=%d\n", fe_sec_mini_cmd
);
1561 utmp
= dev
->cfg
->envelope_mode
<< 5;
1562 ret
= m88ds3103_update_bits(dev
, 0xa2, 0xe0, utmp
);
1566 switch (fe_sec_mini_cmd
) {
1574 dev_dbg(&client
->dev
, "invalid fe_sec_mini_cmd\n");
1579 ret
= regmap_write(dev
->regmap
, 0xa1, burst
);
1583 /* wait DiSEqC TX ready */
1584 #define SEND_BURST_TIMEOUT 40
1585 timeout
= jiffies
+ msecs_to_jiffies(SEND_BURST_TIMEOUT
);
1587 /* DiSEqC ToneBurst period is 12.5 ms */
1588 usleep_range(8500, 12500);
1590 for (utmp
= 1; !time_after(jiffies
, timeout
) && utmp
;) {
1591 ret
= regmap_read(dev
->regmap
, 0xa1, &utmp
);
1594 utmp
= (utmp
>> 6) & 0x1;
1598 dev_dbg(&client
->dev
, "diseqc tx took %u ms\n",
1599 jiffies_to_msecs(jiffies
) -
1600 (jiffies_to_msecs(timeout
) - SEND_BURST_TIMEOUT
));
1602 dev_dbg(&client
->dev
, "diseqc tx timeout\n");
1604 ret
= m88ds3103_update_bits(dev
, 0xa1, 0xc0, 0x40);
1609 ret
= m88ds3103_update_bits(dev
, 0xa2, 0xc0, 0x80);
1620 dev_dbg(&client
->dev
, "failed=%d\n", ret
);
1624 static int m88ds3103_get_tune_settings(struct dvb_frontend
*fe
,
1625 struct dvb_frontend_tune_settings
*s
)
1627 s
->min_delay_ms
= 3000;
1632 static void m88ds3103_release(struct dvb_frontend
*fe
)
1634 struct m88ds3103_dev
*dev
= fe
->demodulator_priv
;
1635 struct i2c_client
*client
= dev
->client
;
1637 i2c_unregister_device(client
);
1640 static int m88ds3103_select(struct i2c_mux_core
*muxc
, u32 chan
)
1642 struct m88ds3103_dev
*dev
= i2c_mux_priv(muxc
);
1643 struct i2c_client
*client
= dev
->client
;
1645 struct i2c_msg msg
= {
1646 .addr
= client
->addr
,
1652 /* Open tuner I2C repeater for 1 xfer, closes automatically */
1653 ret
= __i2c_transfer(client
->adapter
, &msg
, 1);
1655 dev_warn(&client
->dev
, "i2c wr failed=%d\n", ret
);
1665 * XXX: That is wrapper to m88ds3103_probe() via driver core in order to provide
1666 * proper I2C client for legacy media attach binding.
1667 * New users must use I2C client binding directly!
1669 struct dvb_frontend
*m88ds3103_attach(const struct m88ds3103_config
*cfg
,
1670 struct i2c_adapter
*i2c
,
1671 struct i2c_adapter
**tuner_i2c_adapter
)
1673 struct i2c_client
*client
;
1674 struct i2c_board_info board_info
;
1675 struct m88ds3103_platform_data pdata
= {};
1677 pdata
.clk
= cfg
->clock
;
1678 pdata
.i2c_wr_max
= cfg
->i2c_wr_max
;
1679 pdata
.ts_mode
= cfg
->ts_mode
;
1680 pdata
.ts_clk
= cfg
->ts_clk
;
1681 pdata
.ts_clk_pol
= cfg
->ts_clk_pol
;
1682 pdata
.spec_inv
= cfg
->spec_inv
;
1683 pdata
.agc
= cfg
->agc
;
1684 pdata
.agc_inv
= cfg
->agc_inv
;
1685 pdata
.clk_out
= cfg
->clock_out
;
1686 pdata
.envelope_mode
= cfg
->envelope_mode
;
1687 pdata
.lnb_hv_pol
= cfg
->lnb_hv_pol
;
1688 pdata
.lnb_en_pol
= cfg
->lnb_en_pol
;
1689 pdata
.attach_in_use
= true;
1691 memset(&board_info
, 0, sizeof(board_info
));
1692 strscpy(board_info
.type
, "m88ds3103", I2C_NAME_SIZE
);
1693 board_info
.addr
= cfg
->i2c_addr
;
1694 board_info
.platform_data
= &pdata
;
1695 client
= i2c_new_client_device(i2c
, &board_info
);
1696 if (!i2c_client_has_driver(client
))
1699 *tuner_i2c_adapter
= pdata
.get_i2c_adapter(client
);
1700 return pdata
.get_dvb_frontend(client
);
1702 EXPORT_SYMBOL(m88ds3103_attach
);
1704 static const struct dvb_frontend_ops m88ds3103_ops
= {
1705 .delsys
= {SYS_DVBS
, SYS_DVBS2
},
1707 .name
= "Montage Technology M88DS3103",
1708 .frequency_min_hz
= 950 * MHz
,
1709 .frequency_max_hz
= 2150 * MHz
,
1710 .frequency_tolerance_hz
= 5 * MHz
,
1711 .symbol_rate_min
= 1000000,
1712 .symbol_rate_max
= 45000000,
1713 .caps
= FE_CAN_INVERSION_AUTO
|
1725 FE_CAN_2G_MODULATION
1728 .release
= m88ds3103_release
,
1730 .get_tune_settings
= m88ds3103_get_tune_settings
,
1732 .init
= m88ds3103_init
,
1733 .sleep
= m88ds3103_sleep
,
1735 .set_frontend
= m88ds3103_set_frontend
,
1736 .get_frontend
= m88ds3103_get_frontend
,
1738 .read_status
= m88ds3103_read_status
,
1739 .read_snr
= m88ds3103_read_snr
,
1740 .read_ber
= m88ds3103_read_ber
,
1742 .diseqc_send_master_cmd
= m88ds3103_diseqc_send_master_cmd
,
1743 .diseqc_send_burst
= m88ds3103_diseqc_send_burst
,
1745 .set_tone
= m88ds3103_set_tone
,
1746 .set_voltage
= m88ds3103_set_voltage
,
1749 static struct dvb_frontend
*m88ds3103_get_dvb_frontend(struct i2c_client
*client
)
1751 struct m88ds3103_dev
*dev
= i2c_get_clientdata(client
);
1753 dev_dbg(&client
->dev
, "\n");
1758 static struct i2c_adapter
*m88ds3103_get_i2c_adapter(struct i2c_client
*client
)
1760 struct m88ds3103_dev
*dev
= i2c_get_clientdata(client
);
1762 dev_dbg(&client
->dev
, "\n");
1764 return dev
->muxc
->adapter
[0];
1767 static int m88ds3103_probe(struct i2c_client
*client
,
1768 const struct i2c_device_id
*id
)
1770 struct m88ds3103_dev
*dev
;
1771 struct m88ds3103_platform_data
*pdata
= client
->dev
.platform_data
;
1775 dev
= kzalloc(sizeof(*dev
), GFP_KERNEL
);
1781 dev
->client
= client
;
1782 dev
->config
.clock
= pdata
->clk
;
1783 dev
->config
.i2c_wr_max
= pdata
->i2c_wr_max
;
1784 dev
->config
.ts_mode
= pdata
->ts_mode
;
1785 dev
->config
.ts_clk
= pdata
->ts_clk
* 1000;
1786 dev
->config
.ts_clk_pol
= pdata
->ts_clk_pol
;
1787 dev
->config
.spec_inv
= pdata
->spec_inv
;
1788 dev
->config
.agc_inv
= pdata
->agc_inv
;
1789 dev
->config
.clock_out
= pdata
->clk_out
;
1790 dev
->config
.envelope_mode
= pdata
->envelope_mode
;
1791 dev
->config
.agc
= pdata
->agc
;
1792 dev
->config
.lnb_hv_pol
= pdata
->lnb_hv_pol
;
1793 dev
->config
.lnb_en_pol
= pdata
->lnb_en_pol
;
1794 dev
->cfg
= &dev
->config
;
1796 dev
->regmap_config
.reg_bits
= 8;
1797 dev
->regmap_config
.val_bits
= 8;
1798 dev
->regmap_config
.lock_arg
= dev
;
1799 dev
->regmap
= devm_regmap_init_i2c(client
, &dev
->regmap_config
);
1800 if (IS_ERR(dev
->regmap
)) {
1801 ret
= PTR_ERR(dev
->regmap
);
1805 /* 0x00: chip id[6:0], 0x01: chip ver[7:0], 0x02: chip ver[15:8] */
1806 ret
= regmap_read(dev
->regmap
, 0x00, &utmp
);
1810 dev
->chip_id
= utmp
>> 1;
1811 dev
->chiptype
= (u8
)id
->driver_data
;
1813 dev_dbg(&client
->dev
, "chip_id=%02x\n", dev
->chip_id
);
1815 switch (dev
->chip_id
) {
1816 case M88RS6000_CHIP_ID
:
1817 case M88DS3103_CHIP_ID
:
1821 dev_err(&client
->dev
, "Unknown device. Chip_id=%02x\n", dev
->chip_id
);
1825 switch (dev
->cfg
->clock_out
) {
1826 case M88DS3103_CLOCK_OUT_DISABLED
:
1829 case M88DS3103_CLOCK_OUT_ENABLED
:
1832 case M88DS3103_CLOCK_OUT_ENABLED_DIV2
:
1840 if (!pdata
->ts_clk
) {
1845 /* 0x29 register is defined differently for m88rs6000. */
1846 /* set internal tuner address to 0x21 */
1847 if (dev
->chip_id
== M88RS6000_CHIP_ID
)
1850 ret
= regmap_write(dev
->regmap
, 0x29, utmp
);
1855 ret
= m88ds3103_update_bits(dev
, 0x08, 0x01, 0x00);
1858 ret
= m88ds3103_update_bits(dev
, 0x04, 0x01, 0x01);
1861 ret
= m88ds3103_update_bits(dev
, 0x23, 0x10, 0x10);
1865 /* create mux i2c adapter for tuner */
1866 dev
->muxc
= i2c_mux_alloc(client
->adapter
, &client
->dev
, 1, 0, 0,
1867 m88ds3103_select
, NULL
);
1872 dev
->muxc
->priv
= dev
;
1873 ret
= i2c_mux_add_adapter(dev
->muxc
, 0, 0, 0);
1877 /* create dvb_frontend */
1878 memcpy(&dev
->fe
.ops
, &m88ds3103_ops
, sizeof(struct dvb_frontend_ops
));
1879 if (dev
->chiptype
== M88DS3103_CHIPTYPE_3103B
)
1880 strscpy(dev
->fe
.ops
.info
.name
, "Montage Technology M88DS3103B",
1881 sizeof(dev
->fe
.ops
.info
.name
));
1882 else if (dev
->chip_id
== M88RS6000_CHIP_ID
)
1883 strscpy(dev
->fe
.ops
.info
.name
, "Montage Technology M88RS6000",
1884 sizeof(dev
->fe
.ops
.info
.name
));
1885 if (!pdata
->attach_in_use
)
1886 dev
->fe
.ops
.release
= NULL
;
1887 dev
->fe
.demodulator_priv
= dev
;
1888 i2c_set_clientdata(client
, dev
);
1890 /* setup callbacks */
1891 pdata
->get_dvb_frontend
= m88ds3103_get_dvb_frontend
;
1892 pdata
->get_i2c_adapter
= m88ds3103_get_i2c_adapter
;
1894 if (dev
->chiptype
== M88DS3103_CHIPTYPE_3103B
) {
1895 /* enable i2c repeater for tuner */
1896 m88ds3103_update_bits(dev
, 0x11, 0x01, 0x01);
1898 /* get frontend address */
1899 ret
= regmap_read(dev
->regmap
, 0x29, &utmp
);
1902 dev
->dt_addr
= ((utmp
& 0x80) == 0) ? 0x42 >> 1 : 0x40 >> 1;
1903 dev_dbg(&client
->dev
, "dt addr is 0x%02x\n", dev
->dt_addr
);
1905 dev
->dt_client
= i2c_new_dummy_device(client
->adapter
,
1907 if (!dev
->dt_client
) {
1917 dev_dbg(&client
->dev
, "failed=%d\n", ret
);
1921 static int m88ds3103_remove(struct i2c_client
*client
)
1923 struct m88ds3103_dev
*dev
= i2c_get_clientdata(client
);
1925 dev_dbg(&client
->dev
, "\n");
1928 i2c_unregister_device(dev
->dt_client
);
1930 i2c_mux_del_adapters(dev
->muxc
);
1936 static const struct i2c_device_id m88ds3103_id_table
[] = {
1937 {"m88ds3103", M88DS3103_CHIPTYPE_3103
},
1938 {"m88rs6000", M88DS3103_CHIPTYPE_RS6000
},
1939 {"m88ds3103b", M88DS3103_CHIPTYPE_3103B
},
1942 MODULE_DEVICE_TABLE(i2c
, m88ds3103_id_table
);
1944 static struct i2c_driver m88ds3103_driver
= {
1946 .name
= "m88ds3103",
1947 .suppress_bind_attrs
= true,
1949 .probe
= m88ds3103_probe
,
1950 .remove
= m88ds3103_remove
,
1951 .id_table
= m88ds3103_id_table
,
1954 module_i2c_driver(m88ds3103_driver
);
1956 MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
1957 MODULE_DESCRIPTION("Montage Technology M88DS3103 DVB-S/S2 demodulator driver");
1958 MODULE_LICENSE("GPL");
1959 MODULE_FIRMWARE(M88DS3103_FIRMWARE
);
1960 MODULE_FIRMWARE(M88RS6000_FIRMWARE
);
1961 MODULE_FIRMWARE(M88DS3103B_FIRMWARE
);