2 * Driver for it913x-fe Frontend
4 * with support for on chip it9137 integral tuner
6 * Copyright (C) 2011 Malcolm Priestley (tvboxspy@gmail.com)
7 * IT9137 Copyright (C) ITE Tech Inc.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.=
25 #include <linux/module.h>
26 #include <linux/init.h>
27 #include <linux/slab.h>
28 #include <linux/types.h>
30 #include "dvb_frontend.h"
31 #include "it913x-fe.h"
32 #include "it913x-fe-priv.h"
34 static int it913x_debug
;
36 module_param_named(debug
, it913x_debug
, int, 0644);
37 MODULE_PARM_DESC(debug
, "set debugging level (1=info (or-able)).");
39 #define dprintk(level, args...) do { \
40 if (level & it913x_debug) \
41 printk(KERN_DEBUG "it913x-fe: " args); \
44 #define deb_info(args...) dprintk(0x01, args)
45 #define debug_data_snipet(level, name, p) \
46 dprintk(level, name" (%02x%02x%02x%02x%02x%02x%02x%02x)", \
47 *p, *(p+1), *(p+2), *(p+3), *(p+4), \
48 *(p+5), *(p+6), *(p+7));
49 #define info(format, arg...) \
50 printk(KERN_INFO "it913x-fe: " format "\n" , ## arg)
52 struct it913x_fe_state
{
53 struct dvb_frontend frontend
;
54 struct i2c_adapter
*i2c_adap
;
55 struct ite_config
*config
;
58 fe_modulation_t constellation
;
59 fe_transmit_mode_t transmission_mode
;
63 struct adctable
*table
;
64 fe_status_t it913x_status
;
72 static int it913x_read_reg(struct it913x_fe_state
*state
,
73 u32 reg
, u8
*data
, u8 count
)
76 u8 pro
= PRO_DMOD
; /* All reads from demodulator */
78 struct i2c_msg msg
[2] = {
79 { .addr
= state
->i2c_addr
+ (pro
<< 1), .flags
= 0,
80 .buf
= b
, .len
= sizeof(b
) },
81 { .addr
= state
->i2c_addr
+ (pro
<< 1), .flags
= I2C_M_RD
,
82 .buf
= data
, .len
= count
}
84 b
[0] = (u8
) reg
>> 24;
85 b
[1] = (u8
)(reg
>> 16) & 0xff;
86 b
[2] = (u8
)(reg
>> 8) & 0xff;
87 b
[3] = (u8
) reg
& 0xff;
89 ret
= i2c_transfer(state
->i2c_adap
, msg
, 2);
94 static int it913x_read_reg_u8(struct it913x_fe_state
*state
, u32 reg
)
98 ret
= it913x_read_reg(state
, reg
, &b
[0], sizeof(b
));
99 return (ret
< 0) ? -ENODEV
: b
[0];
102 static int it913x_write(struct it913x_fe_state
*state
,
103 u8 pro
, u32 reg
, u8 buf
[], u8 count
)
106 struct i2c_msg msg
[1] = {
107 { .addr
= state
->i2c_addr
+ (pro
<< 1), .flags
= 0,
108 .buf
= b
, .len
= count
+ 4 }
112 b
[0] = (u8
) reg
>> 24;
113 b
[1] = (u8
)(reg
>> 16) & 0xff;
114 b
[2] = (u8
)(reg
>> 8) & 0xff;
115 b
[3] = (u8
) reg
& 0xff;
116 memcpy(&b
[4], buf
, count
);
118 ret
= i2c_transfer(state
->i2c_adap
, msg
, 1);
126 static int it913x_write_reg(struct it913x_fe_state
*state
,
127 u8 pro
, u32 reg
, u32 data
)
134 b
[1] = (data
>> 16) & 0xff;
135 b
[2] = (data
>> 8) & 0xff;
137 /* expand write as needed */
140 else if (data
< 0x1000)
142 else if (data
< 0x100000)
147 ret
= it913x_write(state
, pro
, reg
, &b
[s
], sizeof(b
) - s
);
152 static int it913x_fe_script_loader(struct it913x_fe_state
*state
,
153 struct it913xset
*loadscript
)
156 if (loadscript
== NULL
)
159 for (i
= 0; i
< 1000; ++i
) {
160 if (loadscript
[i
].pro
== 0xff)
162 ret
= it913x_write(state
, loadscript
[i
].pro
,
163 loadscript
[i
].address
,
164 loadscript
[i
].reg
, loadscript
[i
].count
);
171 static int it913x_init_tuner(struct it913x_fe_state
*state
)
175 u8 nv
[] = {48, 32, 24, 16, 12, 8, 6, 4, 2};
178 reg
= it913x_read_reg_u8(state
, 0xec86);
181 state
->tun_clk_mode
= reg
;
182 state
->tun_xtal
= 2000;
190 state
->tun_clk_mode
= reg
;
191 state
->tun_xtal
= 640;
197 reg
= it913x_read_reg_u8(state
, 0xed03);
201 else if (reg
< sizeof(nv
))
206 for (i
= 0; i
< 50; i
++) {
207 ret
= it913x_read_reg(state
, 0xed23, &b
[0], sizeof(b
));
208 reg
= (b
[1] << 8) + b
[0];
215 state
->tun_fn_min
= state
->tun_xtal
* reg
;
216 state
->tun_fn_min
/= (state
->tun_fdiv
* nv_val
);
217 deb_info("Tuner fn_min %d", state
->tun_fn_min
);
219 if (state
->config
->chip_ver
> 1)
222 for (i
= 0; i
< 50; i
++) {
223 reg
= it913x_read_reg_u8(state
, 0xec82);
232 return it913x_write_reg(state
, PRO_DMOD
, 0xed81, val
);
235 static int it9137_set_tuner(struct it913x_fe_state
*state
,
236 u32 bandwidth
, u32 frequency_m
)
238 struct it913xset
*set_tuner
= set_it9137_template
;
240 u32 frequency
= frequency_m
/ 1000;
241 u32 freq
, temp_f
, tmp
;
249 if (state
->config
->firmware_ver
== 1)
250 set_tuner
= set_it9135_template
;
252 set_tuner
= set_it9137_template
;
254 deb_info("Tuner Frequency %d Bandwidth %d", frequency
, bandwidth
);
256 if (frequency
>= 51000 && frequency
<= 440000) {
259 } else if (frequency
> 440000 && frequency
<= 484000) {
262 } else if (frequency
> 484000 && frequency
<= 533000) {
265 } else if (frequency
> 533000 && frequency
<= 587000) {
268 } else if (frequency
> 587000 && frequency
<= 645000) {
271 } else if (frequency
> 645000 && frequency
<= 710000) {
274 } else if (frequency
> 710000 && frequency
<= 782000) {
277 } else if (frequency
> 782000 && frequency
<= 860000) {
280 } else if (frequency
> 1450000 && frequency
<= 1492000) {
283 } else if (frequency
> 1660000 && frequency
<= 1685000) {
288 set_tuner
[0].reg
[0] = lna_band
;
306 set_tuner
[1].reg
[0] = bw
;
307 set_tuner
[2].reg
[0] = 0xa0 | (l_band
<< 3);
309 if (frequency
> 53000 && frequency
<= 74000) {
312 } else if (frequency
> 74000 && frequency
<= 111000) {
315 } else if (frequency
> 111000 && frequency
<= 148000) {
318 } else if (frequency
> 148000 && frequency
<= 222000) {
321 } else if (frequency
> 222000 && frequency
<= 296000) {
324 } else if (frequency
> 296000 && frequency
<= 445000) {
327 } else if (frequency
> 445000 && frequency
<= state
->tun_fn_min
) {
330 } else if (frequency
> state
->tun_fn_min
&& frequency
<= 950000) {
333 } else if (frequency
> 1450000 && frequency
<= 1680000) {
339 reg
= it913x_read_reg_u8(state
, 0xed81);
340 iqik_m_cal
= (u16
)reg
* n_div
;
343 if (state
->tun_clk_mode
== 0)
344 iqik_m_cal
= (iqik_m_cal
* 9) >> 5;
348 iqik_m_cal
= 0x40 - iqik_m_cal
;
349 if (state
->tun_clk_mode
== 0)
350 iqik_m_cal
= ~((iqik_m_cal
* 9) >> 5);
352 iqik_m_cal
= ~(iqik_m_cal
>> 1);
355 temp_f
= frequency
* (u32
)n_div
* (u32
)state
->tun_fdiv
;
356 freq
= temp_f
/ state
->tun_xtal
;
357 tmp
= freq
* state
->tun_xtal
;
359 if ((temp_f
- tmp
) >= (state
->tun_xtal
>> 1))
362 freq
+= (u32
) n
<< 13;
363 /* Frequency OMEGA_IQIK_M_CAL_MID*/
364 temp_f
= freq
+ (u32
)iqik_m_cal
;
366 set_tuner
[3].reg
[0] = temp_f
& 0xff;
367 set_tuner
[4].reg
[0] = (temp_f
>> 8) & 0xff;
369 deb_info("High Frequency = %04x", temp_f
);
371 /* Lower frequency */
372 set_tuner
[5].reg
[0] = freq
& 0xff;
373 set_tuner
[6].reg
[0] = (freq
>> 8) & 0xff;
375 deb_info("low Frequency = %04x", freq
);
377 ret
= it913x_fe_script_loader(state
, set_tuner
);
379 return (ret
< 0) ? -ENODEV
: 0;
382 static int it913x_fe_select_bw(struct it913x_fe_state
*state
,
383 u32 bandwidth
, u32 adcFrequency
)
388 u16 bfsfcw_fftinx_ratio
;
389 u16 fftinx_bfsfcw_ratio
;
394 deb_info("Bandwidth %d Adc %d", bandwidth
, adcFrequency
);
411 ret
= it913x_write_reg(state
, PRO_DMOD
, REG_BW
, bw
);
413 if (state
->table
== NULL
)
417 coeff
[0] = state
->table
[bw
].coeff_1_2048
;
418 coeff
[1] = state
->table
[bw
].coeff_2_2k
;
419 coeff
[2] = state
->table
[bw
].coeff_1_8191
;
420 coeff
[3] = state
->table
[bw
].coeff_1_8192
;
421 coeff
[4] = state
->table
[bw
].coeff_1_8193
;
422 coeff
[5] = state
->table
[bw
].coeff_2_8k
;
423 coeff
[6] = state
->table
[bw
].coeff_1_4096
;
424 coeff
[7] = state
->table
[bw
].coeff_2_4k
;
425 bfsfcw_fftinx_ratio
= state
->table
[bw
].bfsfcw_fftinx_ratio
;
426 fftinx_bfsfcw_ratio
= state
->table
[bw
].fftinx_bfsfcw_ratio
;
429 ret
= it913x_read_reg_u8(state
, ADC_X_2
);
437 /* Build Buffer for COEFF Registers */
438 for (i
= 0; i
< 8; i
++) {
439 if (adcmultiplier
== 1)
441 buffer
[count
++] = (coeff
[i
] >> 24) & 0x3;
442 buffer
[count
++] = (coeff
[i
] >> 16) & 0xff;
443 buffer
[count
++] = (coeff
[i
] >> 8) & 0xff;
444 buffer
[count
++] = coeff
[i
] & 0xff;
447 /* bfsfcw_fftinx_ratio register 0x21-0x22 */
448 buffer
[count
++] = bfsfcw_fftinx_ratio
& 0xff;
449 buffer
[count
++] = (bfsfcw_fftinx_ratio
>> 8) & 0xff;
450 /* fftinx_bfsfcw_ratio register 0x23-0x24 */
451 buffer
[count
++] = fftinx_bfsfcw_ratio
& 0xff;
452 buffer
[count
++] = (fftinx_bfsfcw_ratio
>> 8) & 0xff;
453 /* start at COEFF_1_2048 and write through to fftinx_bfsfcw_ratio*/
454 ret
= it913x_write(state
, PRO_DMOD
, COEFF_1_2048
, buffer
, count
);
456 for (i
= 0; i
< 42; i
+= 8)
457 debug_data_snipet(0x1, "Buffer", &buffer
[i
]);
464 static int it913x_fe_read_status(struct dvb_frontend
*fe
, fe_status_t
*status
)
466 struct it913x_fe_state
*state
= fe
->demodulator_priv
;
468 fe_status_t old_status
= state
->it913x_status
;
471 if (state
->it913x_status
== 0) {
472 ret
= it913x_read_reg_u8(state
, EMPTY_CHANNEL_STATUS
);
474 *status
|= FE_HAS_SIGNAL
;
475 for (i
= 0; i
< 40; i
++) {
476 ret
= it913x_read_reg_u8(state
, MP2IF_SYNC_LK
);
482 *status
|= FE_HAS_CARRIER
485 state
->it913x_status
= *status
;
489 if (state
->it913x_status
& FE_HAS_SYNC
) {
490 ret
= it913x_read_reg_u8(state
, TPSD_LOCK
);
492 *status
|= FE_HAS_LOCK
493 | state
->it913x_status
;
495 state
->it913x_status
= 0;
496 if (old_status
!= state
->it913x_status
)
497 ret
= it913x_write_reg(state
, PRO_LINK
, GPIOH3_O
, ret
);
503 static int it913x_fe_read_signal_strength(struct dvb_frontend
*fe
,
506 struct it913x_fe_state
*state
= fe
->demodulator_priv
;
507 int ret
= it913x_read_reg_u8(state
, SIGNAL_LEVEL
);
508 /*SIGNAL_LEVEL always returns 100%! so using FE_HAS_SIGNAL as switch*/
509 if (state
->it913x_status
& FE_HAS_SIGNAL
)
510 ret
= (ret
* 0xff) / 0x64;
518 static int it913x_fe_read_snr(struct dvb_frontend
*fe
, u16
*snr
)
520 struct it913x_fe_state
*state
= fe
->demodulator_priv
;
523 u32 snr_val
, snr_min
, snr_max
;
526 ret
= it913x_read_reg(state
, 0x2c, reg
, sizeof(reg
));
528 snr_val
= (u32
)(reg
[2] << 16) | (reg
[1] << 8) | reg
[0];
530 ret
|= it913x_read_reg(state
, 0xf78b, reg
, 1);
534 if (state
->transmission_mode
== TRANSMISSION_MODE_2K
)
536 else if (state
->transmission_mode
== TRANSMISSION_MODE_4K
)
539 if (state
->constellation
== QPSK
) {
542 } else if (state
->constellation
== QAM_16
) {
545 } else if (state
->constellation
== QAM_64
) {
551 if (snr_val
< snr_min
)
553 else if (snr_val
< snr_max
) {
554 temp
= (snr_val
- snr_min
) >> 5;
556 temp
/= (snr_max
- snr_min
) >> 5;
561 return (ret
< 0) ? -ENODEV
: 0;
564 static int it913x_fe_read_ber(struct dvb_frontend
*fe
, u32
*ber
)
566 struct it913x_fe_state
*state
= fe
->demodulator_priv
;
569 /* Read Aborted Packets and Pre-Viterbi error rate 5 bytes */
570 ret
= it913x_read_reg(state
, RSD_ABORT_PKT_LSB
, reg
, sizeof(reg
));
571 state
->ucblocks
+= (u32
)(reg
[1] << 8) | reg
[0];
572 *ber
= (u32
)(reg
[4] << 16) | (reg
[3] << 8) | reg
[2];
576 static int it913x_fe_read_ucblocks(struct dvb_frontend
*fe
, u32
*ucblocks
)
578 struct it913x_fe_state
*state
= fe
->demodulator_priv
;
581 /* Aborted Packets */
582 ret
= it913x_read_reg(state
, RSD_ABORT_PKT_LSB
, reg
, sizeof(reg
));
583 state
->ucblocks
+= (u32
)(reg
[1] << 8) | reg
[0];
584 *ucblocks
= state
->ucblocks
;
588 static int it913x_fe_get_frontend(struct dvb_frontend
*fe
)
590 struct dtv_frontend_properties
*p
= &fe
->dtv_property_cache
;
591 struct it913x_fe_state
*state
= fe
->demodulator_priv
;
595 ret
= it913x_read_reg(state
, REG_TPSD_TX_MODE
, reg
, sizeof(reg
));
598 p
->modulation
= fe_con
[reg
[3]];
601 p
->transmission_mode
= fe_mode
[reg
[0]];
604 p
->guard_interval
= fe_gi
[reg
[1]];
607 p
->hierarchy
= fe_hi
[reg
[2]];
609 p
->code_rate_HP
= (reg
[6] < 6) ? fe_code
[reg
[6]] : FEC_NONE
;
610 p
->code_rate_LP
= (reg
[7] < 6) ? fe_code
[reg
[7]] : FEC_NONE
;
612 /* Update internal state to reflect the autodetected props */
613 state
->constellation
= p
->modulation
;
614 state
->transmission_mode
= p
->transmission_mode
;
619 static int it913x_fe_set_frontend(struct dvb_frontend
*fe
)
621 struct dtv_frontend_properties
*p
= &fe
->dtv_property_cache
;
622 struct it913x_fe_state
*state
= fe
->demodulator_priv
;
624 u8 empty_ch
, last_ch
;
626 state
->it913x_status
= 0;
629 ret
= it913x_fe_select_bw(state
, p
->bandwidth_hz
,
630 state
->adcFrequency
);
632 /* Training Mode Off */
633 ret
= it913x_write_reg(state
, PRO_LINK
, TRAINING_MODE
, 0x0);
635 /* Clear Empty Channel */
636 ret
= it913x_write_reg(state
, PRO_DMOD
, EMPTY_CHANNEL_STATUS
, 0x0);
639 ret
= it913x_write_reg(state
, PRO_DMOD
, MP2IF_SYNC_LK
, 0x0);
641 ret
= it913x_write_reg(state
, PRO_LINK
, GPIOH3_O
, 0x1);
643 if ((p
->frequency
>= 51000000) && (p
->frequency
<= 230000000))
645 else if ((p
->frequency
>= 350000000) && (p
->frequency
<= 900000000))
647 else if ((p
->frequency
>= 1450000000) && (p
->frequency
<= 1680000000))
652 ret
= it913x_write_reg(state
, PRO_DMOD
, FREE_BAND
, i
);
654 deb_info("Frontend Set Tuner Type %02x", state
->tuner_type
);
655 switch (state
->tuner_type
) {
662 ret
= it9137_set_tuner(state
,
663 p
->bandwidth_hz
, p
->frequency
);
666 if (fe
->ops
.tuner_ops
.set_params
) {
667 fe
->ops
.tuner_ops
.set_params(fe
);
668 if (fe
->ops
.i2c_gate_ctrl
)
669 fe
->ops
.i2c_gate_ctrl(fe
, 0);
674 ret
= it913x_write_reg(state
, PRO_LINK
, GPIOH3_O
, 0x0);
676 ret
= it913x_write_reg(state
, PRO_DMOD
, TRIGGER_OFSM
, 0x0);
678 for (i
= 0; i
< 40; ++i
) {
679 empty_ch
= it913x_read_reg_u8(state
, EMPTY_CHANNEL_STATUS
);
680 if (last_ch
== 1 && empty_ch
== 1)
682 if (last_ch
== 2 && empty_ch
== 2)
687 for (i
= 0; i
< 40; ++i
) {
688 if (it913x_read_reg_u8(state
, D_TPSD_LOCK
) == 1)
693 state
->frequency
= p
->frequency
;
697 static int it913x_fe_suspend(struct it913x_fe_state
*state
)
702 ret
= it913x_write_reg(state
, PRO_DMOD
, SUSPEND_FLAG
, 0x1);
704 ret
|= it913x_write_reg(state
, PRO_DMOD
, TRIGGER_OFSM
, 0x0);
706 for (i
= 0; i
< 128; i
++) {
707 ret
= it913x_read_reg(state
, SUSPEND_FLAG
, &b
, 1);
715 ret
|= it913x_write_reg(state
, PRO_DMOD
, AFE_MEM0
, 0x8);
717 ret
|= it913x_write_reg(state
, PRO_LINK
, GPIOH3_O
, 0x0);
719 ret
|= it913x_fe_script_loader(state
, it9137_tuner_off
);
721 return (ret
< 0) ? -ENODEV
: 0;
725 /* Power Up Tuner on -> Frontend suspend off -> Tuner clk on */
726 /* Power Down Frontend suspend on -> Tuner clk off -> Tuner off */
728 static int it913x_fe_sleep(struct dvb_frontend
*fe
)
730 struct it913x_fe_state
*state
= fe
->demodulator_priv
;
731 return it913x_fe_suspend(state
);
734 static u32
compute_div(u32 a
, u32 b
, u32 x
)
745 for (i
= 0; i
< x
; i
++) {
754 res
= (c
<< x
) + res
;
759 static int it913x_fe_start(struct it913x_fe_state
*state
)
761 struct it913xset
*set_lna
;
762 struct it913xset
*set_mode
;
764 u8 adf
= (state
->config
->adf
& 0xf);
768 if (state
->config
->chip_ver
== 1)
769 ret
= it913x_init_tuner(state
);
771 info("ADF table value :%02x", adf
);
774 state
->crystalFrequency
= fe_clockTable
[adf
].xtal
;
775 state
->table
= fe_clockTable
[adf
].table
;
776 state
->adcFrequency
= state
->table
->adcFrequency
;
778 adc
= compute_div(state
->adcFrequency
, 1000000ul, 19ul);
779 xtal
= compute_div(state
->crystalFrequency
, 1000000ul, 19ul);
784 /* Set LED indicator on GPIOH3 */
785 ret
= it913x_write_reg(state
, PRO_LINK
, GPIOH3_EN
, 0x1);
786 ret
|= it913x_write_reg(state
, PRO_LINK
, GPIOH3_ON
, 0x1);
787 ret
|= it913x_write_reg(state
, PRO_LINK
, GPIOH3_O
, 0x1);
789 ret
|= it913x_write_reg(state
, PRO_LINK
, 0xf641, state
->tuner_type
);
790 ret
|= it913x_write_reg(state
, PRO_DMOD
, 0xf5ca, 0x01);
791 ret
|= it913x_write_reg(state
, PRO_DMOD
, 0xf715, 0x01);
794 b
[1] = (xtal
>> 8) & 0xff;
795 b
[2] = (xtal
>> 16) & 0xff;
797 ret
|= it913x_write(state
, PRO_DMOD
, XTAL_CLK
, b
, 4);
800 b
[1] = (adc
>> 8) & 0xff;
801 b
[2] = (adc
>> 16) & 0xff;
802 ret
|= it913x_write(state
, PRO_DMOD
, ADC_FREQ
, b
, 3);
804 if (state
->config
->adc_x2
)
805 ret
|= it913x_write_reg(state
, PRO_DMOD
, ADC_X_2
, 0x01);
809 ret
|= it913x_write(state
, PRO_DMOD
, 0x0029, b
, 3);
811 info("Crystal Frequency :%d Adc Frequency :%d ADC X2: %02x",
812 state
->crystalFrequency
, state
->adcFrequency
,
813 state
->config
->adc_x2
);
814 deb_info("Xtal value :%04x Adc value :%04x", xtal
, adc
);
819 /* v1 or v2 tuner script */
820 if (state
->config
->chip_ver
> 1)
821 ret
= it913x_fe_script_loader(state
, it9135_v2
);
823 ret
= it913x_fe_script_loader(state
, it9135_v1
);
828 switch (state
->tuner_type
) {
848 info("Tuner LNA type :%02x", state
->tuner_type
);
850 ret
= it913x_fe_script_loader(state
, set_lna
);
854 if (state
->config
->chip_ver
== 2) {
855 ret
= it913x_write_reg(state
, PRO_DMOD
, TRIGGER_OFSM
, 0x1);
856 ret
|= it913x_write_reg(state
, PRO_LINK
, PADODPU
, 0x0);
857 ret
|= it913x_write_reg(state
, PRO_LINK
, AGC_O_D
, 0x0);
858 ret
|= it913x_init_tuner(state
);
863 /* Always solo frontend */
864 set_mode
= set_solo_fe
;
865 ret
|= it913x_fe_script_loader(state
, set_mode
);
867 ret
|= it913x_fe_suspend(state
);
868 return (ret
< 0) ? -ENODEV
: 0;
871 static int it913x_fe_init(struct dvb_frontend
*fe
)
873 struct it913x_fe_state
*state
= fe
->demodulator_priv
;
875 /* Power Up Tuner - common all versions */
876 ret
= it913x_write_reg(state
, PRO_DMOD
, 0xec40, 0x1);
878 ret
|= it913x_fe_script_loader(state
, init_1
);
880 ret
|= it913x_write_reg(state
, PRO_DMOD
, AFE_MEM0
, 0x0);
882 ret
|= it913x_write_reg(state
, PRO_DMOD
, 0xfba8, 0x0);
884 return (ret
< 0) ? -ENODEV
: 0;
887 static void it913x_fe_release(struct dvb_frontend
*fe
)
889 struct it913x_fe_state
*state
= fe
->demodulator_priv
;
893 static struct dvb_frontend_ops it913x_fe_ofdm_ops
;
895 struct dvb_frontend
*it913x_fe_attach(struct i2c_adapter
*i2c_adap
,
896 u8 i2c_addr
, struct ite_config
*config
)
898 struct it913x_fe_state
*state
= NULL
;
901 /* allocate memory for the internal state */
902 state
= kzalloc(sizeof(struct it913x_fe_state
), GFP_KERNEL
);
908 state
->i2c_adap
= i2c_adap
;
909 state
->i2c_addr
= i2c_addr
;
910 state
->config
= config
;
912 switch (state
->config
->tuner_id_0
) {
918 state
->tuner_type
= state
->config
->tuner_id_0
;
922 state
->tuner_type
= IT9135_38
;
925 ret
= it913x_fe_start(state
);
930 /* create dvb_frontend */
931 memcpy(&state
->frontend
.ops
, &it913x_fe_ofdm_ops
,
932 sizeof(struct dvb_frontend_ops
));
933 state
->frontend
.demodulator_priv
= state
;
935 return &state
->frontend
;
940 EXPORT_SYMBOL(it913x_fe_attach
);
942 static struct dvb_frontend_ops it913x_fe_ofdm_ops
= {
943 .delsys
= { SYS_DVBT
},
945 .name
= "it913x-fe DVB-T",
946 .frequency_min
= 51000000,
947 .frequency_max
= 1680000000,
948 .frequency_stepsize
= 62500,
949 .caps
= FE_CAN_FEC_1_2
| FE_CAN_FEC_2_3
| FE_CAN_FEC_3_4
|
950 FE_CAN_FEC_4_5
| FE_CAN_FEC_5_6
| FE_CAN_FEC_6_7
|
951 FE_CAN_FEC_7_8
| FE_CAN_FEC_8_9
| FE_CAN_FEC_AUTO
|
952 FE_CAN_QAM_16
| FE_CAN_QAM_64
| FE_CAN_QAM_AUTO
|
953 FE_CAN_TRANSMISSION_MODE_AUTO
|
954 FE_CAN_GUARD_INTERVAL_AUTO
|
955 FE_CAN_HIERARCHY_AUTO
,
958 .release
= it913x_fe_release
,
960 .init
= it913x_fe_init
,
961 .sleep
= it913x_fe_sleep
,
963 .set_frontend
= it913x_fe_set_frontend
,
964 .get_frontend
= it913x_fe_get_frontend
,
966 .read_status
= it913x_fe_read_status
,
967 .read_signal_strength
= it913x_fe_read_signal_strength
,
968 .read_snr
= it913x_fe_read_snr
,
969 .read_ber
= it913x_fe_read_ber
,
970 .read_ucblocks
= it913x_fe_read_ucblocks
,
973 MODULE_DESCRIPTION("it913x Frontend and it9137 tuner");
974 MODULE_AUTHOR("Malcolm Priestley tvboxspy@gmail.com");
975 MODULE_VERSION("1.13");
976 MODULE_LICENSE("GPL");