2 * Afatech AF9033 demodulator driver
4 * Copyright (C) 2009 Antti Palosaari <crope@iki.fi>
5 * Copyright (C) 2012 Antti Palosaari <crope@iki.fi>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "af9033_priv.h"
25 struct i2c_adapter
*i2c
;
26 struct dvb_frontend fe
;
27 struct af9033_config cfg
;
30 bool ts_mode_parallel
;
35 unsigned long last_stat_check
;
38 /* write multiple registers */
39 static int af9033_wr_regs(struct af9033_state
*state
, u32 reg
, const u8
*val
,
44 struct i2c_msg msg
[1] = {
46 .addr
= state
->cfg
.i2c_addr
,
53 buf
[0] = (reg
>> 16) & 0xff;
54 buf
[1] = (reg
>> 8) & 0xff;
55 buf
[2] = (reg
>> 0) & 0xff;
56 memcpy(&buf
[3], val
, len
);
58 ret
= i2c_transfer(state
->i2c
, msg
, 1);
62 dev_warn(&state
->i2c
->dev
, "%s: i2c wr failed=%d reg=%06x " \
63 "len=%d\n", KBUILD_MODNAME
, ret
, reg
, len
);
70 /* read multiple registers */
71 static int af9033_rd_regs(struct af9033_state
*state
, u32 reg
, u8
*val
, int len
)
74 u8 buf
[3] = { (reg
>> 16) & 0xff, (reg
>> 8) & 0xff,
76 struct i2c_msg msg
[2] = {
78 .addr
= state
->cfg
.i2c_addr
,
83 .addr
= state
->cfg
.i2c_addr
,
90 ret
= i2c_transfer(state
->i2c
, msg
, 2);
94 dev_warn(&state
->i2c
->dev
, "%s: i2c rd failed=%d reg=%06x " \
95 "len=%d\n", KBUILD_MODNAME
, ret
, reg
, len
);
103 /* write single register */
104 static int af9033_wr_reg(struct af9033_state
*state
, u32 reg
, u8 val
)
106 return af9033_wr_regs(state
, reg
, &val
, 1);
109 /* read single register */
110 static int af9033_rd_reg(struct af9033_state
*state
, u32 reg
, u8
*val
)
112 return af9033_rd_regs(state
, reg
, val
, 1);
115 /* write single register with mask */
116 static int af9033_wr_reg_mask(struct af9033_state
*state
, u32 reg
, u8 val
,
122 /* no need for read if whole reg is written */
124 ret
= af9033_rd_regs(state
, reg
, &tmp
, 1);
133 return af9033_wr_regs(state
, reg
, &val
, 1);
136 /* read single register with mask */
137 static int af9033_rd_reg_mask(struct af9033_state
*state
, u32 reg
, u8
*val
,
143 ret
= af9033_rd_regs(state
, reg
, &tmp
, 1);
149 /* find position of the first bit */
150 for (i
= 0; i
< 8; i
++) {
151 if ((mask
>> i
) & 0x01)
159 /* write reg val table using reg addr auto increment */
160 static int af9033_wr_reg_val_tab(struct af9033_state
*state
,
161 const struct reg_val
*tab
, int tab_len
)
166 dev_dbg(&state
->i2c
->dev
, "%s: tab_len=%d\n", __func__
, tab_len
);
168 for (i
= 0, j
= 0; i
< tab_len
; i
++) {
171 if (i
== tab_len
- 1 || tab
[i
].reg
!= tab
[i
+ 1].reg
- 1) {
172 ret
= af9033_wr_regs(state
, tab
[i
].reg
- j
, buf
, j
+ 1);
185 dev_dbg(&state
->i2c
->dev
, "%s: failed=%d\n", __func__
, ret
);
190 static u32
af9033_div(struct af9033_state
*state
, u32 a
, u32 b
, u32 x
)
194 dev_dbg(&state
->i2c
->dev
, "%s: a=%d b=%d x=%d\n", __func__
, a
, b
, x
);
201 for (i
= 0; i
< x
; i
++) {
209 r
= (c
<< (u32
)x
) + r
;
211 dev_dbg(&state
->i2c
->dev
, "%s: a=%d b=%d x=%d r=%d r=%x\n",
212 __func__
, a
, b
, x
, r
, r
);
217 static void af9033_release(struct dvb_frontend
*fe
)
219 struct af9033_state
*state
= fe
->demodulator_priv
;
224 static int af9033_init(struct dvb_frontend
*fe
)
226 struct af9033_state
*state
= fe
->demodulator_priv
;
228 const struct reg_val
*init
;
230 u32 adc_cw
, clock_cw
;
231 struct reg_val_mask tab
[] = {
232 { 0x80fb24, 0x00, 0x08 },
233 { 0x80004c, 0x00, 0xff },
234 { 0x00f641, state
->cfg
.tuner
, 0xff },
235 { 0x80f5ca, 0x01, 0x01 },
236 { 0x80f715, 0x01, 0x01 },
237 { 0x00f41f, 0x04, 0x04 },
238 { 0x00f41a, 0x01, 0x01 },
239 { 0x80f731, 0x00, 0x01 },
240 { 0x00d91e, 0x00, 0x01 },
241 { 0x00d919, 0x00, 0x01 },
242 { 0x80f732, 0x00, 0x01 },
243 { 0x00d91f, 0x00, 0x01 },
244 { 0x00d91a, 0x00, 0x01 },
245 { 0x80f730, 0x00, 0x01 },
246 { 0x80f778, 0x00, 0xff },
247 { 0x80f73c, 0x01, 0x01 },
248 { 0x80f776, 0x00, 0x01 },
249 { 0x00d8fd, 0x01, 0xff },
250 { 0x00d830, 0x01, 0xff },
251 { 0x00d831, 0x00, 0xff },
252 { 0x00d832, 0x00, 0xff },
253 { 0x80f985, state
->ts_mode_serial
, 0x01 },
254 { 0x80f986, state
->ts_mode_parallel
, 0x01 },
255 { 0x00d827, 0x00, 0xff },
256 { 0x00d829, 0x00, 0xff },
257 { 0x800045, state
->cfg
.adc_multiplier
, 0xff },
260 /* program clock control */
261 clock_cw
= af9033_div(state
, state
->cfg
.clock
, 1000000ul, 19ul);
262 buf
[0] = (clock_cw
>> 0) & 0xff;
263 buf
[1] = (clock_cw
>> 8) & 0xff;
264 buf
[2] = (clock_cw
>> 16) & 0xff;
265 buf
[3] = (clock_cw
>> 24) & 0xff;
267 dev_dbg(&state
->i2c
->dev
, "%s: clock=%d clock_cw=%08x\n",
268 __func__
, state
->cfg
.clock
, clock_cw
);
270 ret
= af9033_wr_regs(state
, 0x800025, buf
, 4);
274 /* program ADC control */
275 for (i
= 0; i
< ARRAY_SIZE(clock_adc_lut
); i
++) {
276 if (clock_adc_lut
[i
].clock
== state
->cfg
.clock
)
280 adc_cw
= af9033_div(state
, clock_adc_lut
[i
].adc
, 1000000ul, 19ul);
281 buf
[0] = (adc_cw
>> 0) & 0xff;
282 buf
[1] = (adc_cw
>> 8) & 0xff;
283 buf
[2] = (adc_cw
>> 16) & 0xff;
285 dev_dbg(&state
->i2c
->dev
, "%s: adc=%d adc_cw=%06x\n",
286 __func__
, clock_adc_lut
[i
].adc
, adc_cw
);
288 ret
= af9033_wr_regs(state
, 0x80f1cd, buf
, 3);
292 /* program register table */
293 for (i
= 0; i
< ARRAY_SIZE(tab
); i
++) {
294 ret
= af9033_wr_reg_mask(state
, tab
[i
].reg
, tab
[i
].val
,
300 /* settings for TS interface */
301 if (state
->cfg
.ts_mode
== AF9033_TS_MODE_USB
) {
302 ret
= af9033_wr_reg_mask(state
, 0x80f9a5, 0x00, 0x01);
306 ret
= af9033_wr_reg_mask(state
, 0x80f9b5, 0x01, 0x01);
310 ret
= af9033_wr_reg_mask(state
, 0x80f990, 0x00, 0x01);
314 ret
= af9033_wr_reg_mask(state
, 0x80f9b5, 0x00, 0x01);
319 /* load OFSM settings */
320 dev_dbg(&state
->i2c
->dev
, "%s: load ofsm settings\n", __func__
);
321 switch (state
->cfg
.tuner
) {
322 case AF9033_TUNER_IT9135_38
:
323 case AF9033_TUNER_IT9135_51
:
324 case AF9033_TUNER_IT9135_52
:
325 len
= ARRAY_SIZE(ofsm_init_it9135_v1
);
326 init
= ofsm_init_it9135_v1
;
328 case AF9033_TUNER_IT9135_60
:
329 case AF9033_TUNER_IT9135_61
:
330 case AF9033_TUNER_IT9135_62
:
331 len
= ARRAY_SIZE(ofsm_init_it9135_v2
);
332 init
= ofsm_init_it9135_v2
;
335 len
= ARRAY_SIZE(ofsm_init
);
340 ret
= af9033_wr_reg_val_tab(state
, init
, len
);
344 /* load tuner specific settings */
345 dev_dbg(&state
->i2c
->dev
, "%s: load tuner specific settings\n",
347 switch (state
->cfg
.tuner
) {
348 case AF9033_TUNER_TUA9001
:
349 len
= ARRAY_SIZE(tuner_init_tua9001
);
350 init
= tuner_init_tua9001
;
352 case AF9033_TUNER_FC0011
:
353 len
= ARRAY_SIZE(tuner_init_fc0011
);
354 init
= tuner_init_fc0011
;
356 case AF9033_TUNER_MXL5007T
:
357 len
= ARRAY_SIZE(tuner_init_mxl5007t
);
358 init
= tuner_init_mxl5007t
;
360 case AF9033_TUNER_TDA18218
:
361 len
= ARRAY_SIZE(tuner_init_tda18218
);
362 init
= tuner_init_tda18218
;
364 case AF9033_TUNER_FC2580
:
365 len
= ARRAY_SIZE(tuner_init_fc2580
);
366 init
= tuner_init_fc2580
;
368 case AF9033_TUNER_FC0012
:
369 len
= ARRAY_SIZE(tuner_init_fc0012
);
370 init
= tuner_init_fc0012
;
372 case AF9033_TUNER_IT9135_38
:
373 len
= ARRAY_SIZE(tuner_init_it9135_38
);
374 init
= tuner_init_it9135_38
;
376 case AF9033_TUNER_IT9135_51
:
377 len
= ARRAY_SIZE(tuner_init_it9135_51
);
378 init
= tuner_init_it9135_51
;
380 case AF9033_TUNER_IT9135_52
:
381 len
= ARRAY_SIZE(tuner_init_it9135_52
);
382 init
= tuner_init_it9135_52
;
384 case AF9033_TUNER_IT9135_60
:
385 len
= ARRAY_SIZE(tuner_init_it9135_60
);
386 init
= tuner_init_it9135_60
;
388 case AF9033_TUNER_IT9135_61
:
389 len
= ARRAY_SIZE(tuner_init_it9135_61
);
390 init
= tuner_init_it9135_61
;
392 case AF9033_TUNER_IT9135_62
:
393 len
= ARRAY_SIZE(tuner_init_it9135_62
);
394 init
= tuner_init_it9135_62
;
397 dev_dbg(&state
->i2c
->dev
, "%s: unsupported tuner ID=%d\n",
398 __func__
, state
->cfg
.tuner
);
403 ret
= af9033_wr_reg_val_tab(state
, init
, len
);
407 if (state
->cfg
.ts_mode
== AF9033_TS_MODE_SERIAL
) {
408 ret
= af9033_wr_reg_mask(state
, 0x00d91c, 0x01, 0x01);
412 ret
= af9033_wr_reg_mask(state
, 0x00d917, 0x00, 0x01);
416 ret
= af9033_wr_reg_mask(state
, 0x00d916, 0x00, 0x01);
421 switch (state
->cfg
.tuner
) {
422 case AF9033_TUNER_IT9135_60
:
423 case AF9033_TUNER_IT9135_61
:
424 case AF9033_TUNER_IT9135_62
:
425 ret
= af9033_wr_reg(state
, 0x800000, 0x01);
430 state
->bandwidth_hz
= 0; /* force to program all parameters */
435 dev_dbg(&state
->i2c
->dev
, "%s: failed=%d\n", __func__
, ret
);
440 static int af9033_sleep(struct dvb_frontend
*fe
)
442 struct af9033_state
*state
= fe
->demodulator_priv
;
446 ret
= af9033_wr_reg(state
, 0x80004c, 1);
450 ret
= af9033_wr_reg(state
, 0x800000, 0);
454 for (i
= 100, tmp
= 1; i
&& tmp
; i
--) {
455 ret
= af9033_rd_reg(state
, 0x80004c, &tmp
);
459 usleep_range(200, 10000);
462 dev_dbg(&state
->i2c
->dev
, "%s: loop=%d\n", __func__
, i
);
469 ret
= af9033_wr_reg_mask(state
, 0x80fb24, 0x08, 0x08);
473 /* prevent current leak (?) */
474 if (state
->cfg
.ts_mode
== AF9033_TS_MODE_SERIAL
) {
475 /* enable parallel TS */
476 ret
= af9033_wr_reg_mask(state
, 0x00d917, 0x00, 0x01);
480 ret
= af9033_wr_reg_mask(state
, 0x00d916, 0x01, 0x01);
488 dev_dbg(&state
->i2c
->dev
, "%s: failed=%d\n", __func__
, ret
);
493 static int af9033_get_tune_settings(struct dvb_frontend
*fe
,
494 struct dvb_frontend_tune_settings
*fesettings
)
496 /* 800 => 2000 because IT9135 v2 is slow to gain lock */
497 fesettings
->min_delay_ms
= 2000;
498 fesettings
->step_size
= 0;
499 fesettings
->max_drift
= 0;
504 static int af9033_set_frontend(struct dvb_frontend
*fe
)
506 struct af9033_state
*state
= fe
->demodulator_priv
;
507 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
508 int ret
, i
, spec_inv
, sampling_freq
;
509 u8 tmp
, buf
[3], bandwidth_reg_val
;
510 u32 if_frequency
, freq_cw
, adc_freq
;
512 dev_dbg(&state
->i2c
->dev
, "%s: frequency=%d bandwidth_hz=%d\n",
513 __func__
, c
->frequency
, c
->bandwidth_hz
);
515 /* check bandwidth */
516 switch (c
->bandwidth_hz
) {
518 bandwidth_reg_val
= 0x00;
521 bandwidth_reg_val
= 0x01;
524 bandwidth_reg_val
= 0x02;
527 dev_dbg(&state
->i2c
->dev
, "%s: invalid bandwidth_hz\n",
534 if (fe
->ops
.tuner_ops
.set_params
)
535 fe
->ops
.tuner_ops
.set_params(fe
);
537 /* program CFOE coefficients */
538 if (c
->bandwidth_hz
!= state
->bandwidth_hz
) {
539 for (i
= 0; i
< ARRAY_SIZE(coeff_lut
); i
++) {
540 if (coeff_lut
[i
].clock
== state
->cfg
.clock
&&
541 coeff_lut
[i
].bandwidth_hz
== c
->bandwidth_hz
) {
545 ret
= af9033_wr_regs(state
, 0x800001,
546 coeff_lut
[i
].val
, sizeof(coeff_lut
[i
].val
));
549 /* program frequency control */
550 if (c
->bandwidth_hz
!= state
->bandwidth_hz
) {
551 spec_inv
= state
->cfg
.spec_inv
? -1 : 1;
553 for (i
= 0; i
< ARRAY_SIZE(clock_adc_lut
); i
++) {
554 if (clock_adc_lut
[i
].clock
== state
->cfg
.clock
)
557 adc_freq
= clock_adc_lut
[i
].adc
;
559 /* get used IF frequency */
560 if (fe
->ops
.tuner_ops
.get_if_frequency
)
561 fe
->ops
.tuner_ops
.get_if_frequency(fe
, &if_frequency
);
565 sampling_freq
= if_frequency
;
567 while (sampling_freq
> (adc_freq
/ 2))
568 sampling_freq
-= adc_freq
;
570 if (sampling_freq
>= 0)
575 freq_cw
= af9033_div(state
, sampling_freq
, adc_freq
, 23ul);
578 freq_cw
= 0x800000 - freq_cw
;
580 if (state
->cfg
.adc_multiplier
== AF9033_ADC_MULTIPLIER_2X
)
583 buf
[0] = (freq_cw
>> 0) & 0xff;
584 buf
[1] = (freq_cw
>> 8) & 0xff;
585 buf
[2] = (freq_cw
>> 16) & 0x7f;
587 /* FIXME: there seems to be calculation error here... */
588 if (if_frequency
== 0)
591 ret
= af9033_wr_regs(state
, 0x800029, buf
, 3);
595 state
->bandwidth_hz
= c
->bandwidth_hz
;
598 ret
= af9033_wr_reg_mask(state
, 0x80f904, bandwidth_reg_val
, 0x03);
602 ret
= af9033_wr_reg(state
, 0x800040, 0x00);
606 ret
= af9033_wr_reg(state
, 0x800047, 0x00);
610 ret
= af9033_wr_reg_mask(state
, 0x80f999, 0x00, 0x01);
614 if (c
->frequency
<= 230000000)
615 tmp
= 0x00; /* VHF */
617 tmp
= 0x01; /* UHF */
619 ret
= af9033_wr_reg(state
, 0x80004b, tmp
);
623 ret
= af9033_wr_reg(state
, 0x800000, 0x00);
630 dev_dbg(&state
->i2c
->dev
, "%s: failed=%d\n", __func__
, ret
);
635 static int af9033_get_frontend(struct dvb_frontend
*fe
)
637 struct af9033_state
*state
= fe
->demodulator_priv
;
638 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
642 dev_dbg(&state
->i2c
->dev
, "%s:\n", __func__
);
644 /* read all needed registers */
645 ret
= af9033_rd_regs(state
, 0x80f900, buf
, sizeof(buf
));
649 switch ((buf
[0] >> 0) & 3) {
651 c
->transmission_mode
= TRANSMISSION_MODE_2K
;
654 c
->transmission_mode
= TRANSMISSION_MODE_8K
;
658 switch ((buf
[1] >> 0) & 3) {
660 c
->guard_interval
= GUARD_INTERVAL_1_32
;
663 c
->guard_interval
= GUARD_INTERVAL_1_16
;
666 c
->guard_interval
= GUARD_INTERVAL_1_8
;
669 c
->guard_interval
= GUARD_INTERVAL_1_4
;
673 switch ((buf
[2] >> 0) & 7) {
675 c
->hierarchy
= HIERARCHY_NONE
;
678 c
->hierarchy
= HIERARCHY_1
;
681 c
->hierarchy
= HIERARCHY_2
;
684 c
->hierarchy
= HIERARCHY_4
;
688 switch ((buf
[3] >> 0) & 3) {
690 c
->modulation
= QPSK
;
693 c
->modulation
= QAM_16
;
696 c
->modulation
= QAM_64
;
700 switch ((buf
[4] >> 0) & 3) {
702 c
->bandwidth_hz
= 6000000;
705 c
->bandwidth_hz
= 7000000;
708 c
->bandwidth_hz
= 8000000;
712 switch ((buf
[6] >> 0) & 7) {
714 c
->code_rate_HP
= FEC_1_2
;
717 c
->code_rate_HP
= FEC_2_3
;
720 c
->code_rate_HP
= FEC_3_4
;
723 c
->code_rate_HP
= FEC_5_6
;
726 c
->code_rate_HP
= FEC_7_8
;
729 c
->code_rate_HP
= FEC_NONE
;
733 switch ((buf
[7] >> 0) & 7) {
735 c
->code_rate_LP
= FEC_1_2
;
738 c
->code_rate_LP
= FEC_2_3
;
741 c
->code_rate_LP
= FEC_3_4
;
744 c
->code_rate_LP
= FEC_5_6
;
747 c
->code_rate_LP
= FEC_7_8
;
750 c
->code_rate_LP
= FEC_NONE
;
757 dev_dbg(&state
->i2c
->dev
, "%s: failed=%d\n", __func__
, ret
);
762 static int af9033_read_status(struct dvb_frontend
*fe
, fe_status_t
*status
)
764 struct af9033_state
*state
= fe
->demodulator_priv
;
770 /* radio channel status, 0=no result, 1=has signal, 2=no signal */
771 ret
= af9033_rd_reg(state
, 0x800047, &tmp
);
777 *status
|= FE_HAS_SIGNAL
;
781 ret
= af9033_rd_reg_mask(state
, 0x80f5a9, &tmp
, 0x01);
786 *status
|= FE_HAS_SIGNAL
| FE_HAS_CARRIER
|
790 ret
= af9033_rd_reg_mask(state
, 0x80f999, &tmp
, 0x01);
795 *status
|= FE_HAS_SIGNAL
| FE_HAS_CARRIER
|
796 FE_HAS_VITERBI
| FE_HAS_SYNC
|
803 dev_dbg(&state
->i2c
->dev
, "%s: failed=%d\n", __func__
, ret
);
808 static int af9033_read_snr(struct dvb_frontend
*fe
, u16
*snr
)
810 struct af9033_state
*state
= fe
->demodulator_priv
;
814 const struct val_snr
*uninitialized_var(snr_lut
);
817 ret
= af9033_rd_regs(state
, 0x80002c, buf
, 3);
821 snr_val
= (buf
[2] << 16) | (buf
[1] << 8) | buf
[0];
823 /* read current modulation */
824 ret
= af9033_rd_reg(state
, 0x80f903, &tmp
);
828 switch ((tmp
>> 0) & 3) {
830 len
= ARRAY_SIZE(qpsk_snr_lut
);
831 snr_lut
= qpsk_snr_lut
;
834 len
= ARRAY_SIZE(qam16_snr_lut
);
835 snr_lut
= qam16_snr_lut
;
838 len
= ARRAY_SIZE(qam64_snr_lut
);
839 snr_lut
= qam64_snr_lut
;
845 for (i
= 0; i
< len
; i
++) {
846 tmp
= snr_lut
[i
].snr
;
848 if (snr_val
< snr_lut
[i
].val
)
852 *snr
= tmp
* 10; /* dB/10 */
857 dev_dbg(&state
->i2c
->dev
, "%s: failed=%d\n", __func__
, ret
);
862 static int af9033_read_signal_strength(struct dvb_frontend
*fe
, u16
*strength
)
864 struct af9033_state
*state
= fe
->demodulator_priv
;
868 /* read signal strength of 0-100 scale */
869 ret
= af9033_rd_reg(state
, 0x800048, &strength2
);
873 /* scale value to 0x0000-0xffff */
874 *strength
= strength2
* 0xffff / 100;
879 dev_dbg(&state
->i2c
->dev
, "%s: failed=%d\n", __func__
, ret
);
884 static int af9033_update_ch_stat(struct af9033_state
*state
)
887 u32 err_cnt
, bit_cnt
;
891 /* only update data every half second */
892 if (time_after(jiffies
, state
->last_stat_check
+ msecs_to_jiffies(500))) {
893 ret
= af9033_rd_regs(state
, 0x800032, buf
, sizeof(buf
));
896 /* in 8 byte packets? */
897 abort_cnt
= (buf
[1] << 8) + buf
[0];
899 err_cnt
= (buf
[4] << 16) + (buf
[3] << 8) + buf
[2];
900 /* in 8 byte packets? always(?) 0x2710 = 10000 */
901 bit_cnt
= (buf
[6] << 8) + buf
[5];
903 if (bit_cnt
< abort_cnt
) {
905 state
->ber
= 0xffffffff;
907 /* 8 byte packets, that have not been rejected already */
908 bit_cnt
-= (u32
)abort_cnt
;
910 state
->ber
= 0xffffffff;
912 err_cnt
-= (u32
)abort_cnt
* 8 * 8;
914 state
->ber
= err_cnt
* (0xffffffff / bit_cnt
);
917 state
->ucb
+= abort_cnt
;
918 state
->last_stat_check
= jiffies
;
923 dev_dbg(&state
->i2c
->dev
, "%s: failed=%d\n", __func__
, ret
);
928 static int af9033_read_ber(struct dvb_frontend
*fe
, u32
*ber
)
930 struct af9033_state
*state
= fe
->demodulator_priv
;
933 ret
= af9033_update_ch_stat(state
);
942 static int af9033_read_ucblocks(struct dvb_frontend
*fe
, u32
*ucblocks
)
944 struct af9033_state
*state
= fe
->demodulator_priv
;
947 ret
= af9033_update_ch_stat(state
);
951 *ucblocks
= state
->ucb
;
956 static int af9033_i2c_gate_ctrl(struct dvb_frontend
*fe
, int enable
)
958 struct af9033_state
*state
= fe
->demodulator_priv
;
961 dev_dbg(&state
->i2c
->dev
, "%s: enable=%d\n", __func__
, enable
);
963 ret
= af9033_wr_reg_mask(state
, 0x00fa04, enable
, 0x01);
970 dev_dbg(&state
->i2c
->dev
, "%s: failed=%d\n", __func__
, ret
);
975 static struct dvb_frontend_ops af9033_ops
;
977 struct dvb_frontend
*af9033_attach(const struct af9033_config
*config
,
978 struct i2c_adapter
*i2c
)
981 struct af9033_state
*state
;
984 dev_dbg(&i2c
->dev
, "%s:\n", __func__
);
986 /* allocate memory for the internal state */
987 state
= kzalloc(sizeof(struct af9033_state
), GFP_KERNEL
);
991 /* setup the state */
993 memcpy(&state
->cfg
, config
, sizeof(struct af9033_config
));
995 if (state
->cfg
.clock
!= 12000000) {
996 dev_err(&state
->i2c
->dev
, "%s: af9033: unsupported clock=%d, " \
997 "only 12000000 Hz is supported currently\n",
998 KBUILD_MODNAME
, state
->cfg
.clock
);
1002 /* firmware version */
1003 ret
= af9033_rd_regs(state
, 0x0083e9, &buf
[0], 4);
1007 ret
= af9033_rd_regs(state
, 0x804191, &buf
[4], 4);
1011 dev_info(&state
->i2c
->dev
, "%s: firmware version: LINK=%d.%d.%d.%d " \
1012 "OFDM=%d.%d.%d.%d\n", KBUILD_MODNAME
, buf
[0], buf
[1],
1013 buf
[2], buf
[3], buf
[4], buf
[5], buf
[6], buf
[7]);
1016 switch (state
->cfg
.tuner
) {
1017 case AF9033_TUNER_IT9135_38
:
1018 case AF9033_TUNER_IT9135_51
:
1019 case AF9033_TUNER_IT9135_52
:
1020 case AF9033_TUNER_IT9135_60
:
1021 case AF9033_TUNER_IT9135_61
:
1022 case AF9033_TUNER_IT9135_62
:
1023 /* IT9135 did not like to sleep at that early */
1026 ret
= af9033_wr_reg(state
, 0x80004c, 1);
1030 ret
= af9033_wr_reg(state
, 0x800000, 0);
1035 /* configure internal TS mode */
1036 switch (state
->cfg
.ts_mode
) {
1037 case AF9033_TS_MODE_PARALLEL
:
1038 state
->ts_mode_parallel
= true;
1040 case AF9033_TS_MODE_SERIAL
:
1041 state
->ts_mode_serial
= true;
1043 case AF9033_TS_MODE_USB
:
1044 /* usb mode for AF9035 */
1049 /* create dvb_frontend */
1050 memcpy(&state
->fe
.ops
, &af9033_ops
, sizeof(struct dvb_frontend_ops
));
1051 state
->fe
.demodulator_priv
= state
;
1059 EXPORT_SYMBOL(af9033_attach
);
1061 static struct dvb_frontend_ops af9033_ops
= {
1062 .delsys
= { SYS_DVBT
},
1064 .name
= "Afatech AF9033 (DVB-T)",
1065 .frequency_min
= 174000000,
1066 .frequency_max
= 862000000,
1067 .frequency_stepsize
= 250000,
1068 .frequency_tolerance
= 0,
1069 .caps
= FE_CAN_FEC_1_2
|
1079 FE_CAN_TRANSMISSION_MODE_AUTO
|
1080 FE_CAN_GUARD_INTERVAL_AUTO
|
1081 FE_CAN_HIERARCHY_AUTO
|
1086 .release
= af9033_release
,
1088 .init
= af9033_init
,
1089 .sleep
= af9033_sleep
,
1091 .get_tune_settings
= af9033_get_tune_settings
,
1092 .set_frontend
= af9033_set_frontend
,
1093 .get_frontend
= af9033_get_frontend
,
1095 .read_status
= af9033_read_status
,
1096 .read_snr
= af9033_read_snr
,
1097 .read_signal_strength
= af9033_read_signal_strength
,
1098 .read_ber
= af9033_read_ber
,
1099 .read_ucblocks
= af9033_read_ucblocks
,
1101 .i2c_gate_ctrl
= af9033_i2c_gate_ctrl
,
1104 MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
1105 MODULE_DESCRIPTION("Afatech AF9033 DVB-T demodulator driver");
1106 MODULE_LICENSE("GPL");