1 // SPDX-License-Identifier: GPL-2.0-only
2 /* DVB frontend part of the Linux driver for TwinhanDTV Alpha/MagicBoxII USB2.0
5 * Copyright (C) 2004-5 Patrick Boettcher (patrick.boettcher@posteo.de)
7 * Thanks to Twinhan who kindly provided hardware and information.
9 * see Documentation/media/dvb-drivers/dvb-usb.rst for more information
13 /* It is a Zarlink MT352 within a Samsung Tuner (DNOS404ZH102A) - 040929 - AAT
15 * Programming is hidden inside the firmware, so set_frontend is very easy.
16 * Even though there is a Firmware command that one can use to access the demod
17 * via its registers. This is used for status information.
20 struct vp7045_fe_state
{
21 struct dvb_frontend fe
;
22 struct dvb_usb_device
*d
;
25 static int vp7045_fe_read_status(struct dvb_frontend
*fe
,
26 enum fe_status
*status
)
28 struct vp7045_fe_state
*state
= fe
->demodulator_priv
;
29 u8 s0
= vp7045_read_reg(state
->d
,0x00),
30 s1
= vp7045_read_reg(state
->d
,0x01),
31 s3
= vp7045_read_reg(state
->d
,0x03);
35 *status
|= FE_HAS_CARRIER
;
37 *status
|= FE_HAS_VITERBI
;
39 *status
|= FE_HAS_LOCK
;
41 *status
|= FE_HAS_SYNC
;
43 *status
|= FE_HAS_SIGNAL
;
45 if ((*status
& (FE_HAS_CARRIER
| FE_HAS_VITERBI
| FE_HAS_SYNC
)) !=
46 (FE_HAS_CARRIER
| FE_HAS_VITERBI
| FE_HAS_SYNC
))
47 *status
&= ~FE_HAS_LOCK
;
52 static int vp7045_fe_read_ber(struct dvb_frontend
* fe
, u32
*ber
)
54 struct vp7045_fe_state
*state
= fe
->demodulator_priv
;
55 *ber
= (vp7045_read_reg(state
->d
, 0x0D) << 16) |
56 (vp7045_read_reg(state
->d
, 0x0E) << 8) |
57 vp7045_read_reg(state
->d
, 0x0F);
61 static int vp7045_fe_read_unc_blocks(struct dvb_frontend
* fe
, u32
*unc
)
63 struct vp7045_fe_state
*state
= fe
->demodulator_priv
;
64 *unc
= (vp7045_read_reg(state
->d
, 0x10) << 8) |
65 vp7045_read_reg(state
->d
, 0x11);
69 static int vp7045_fe_read_signal_strength(struct dvb_frontend
* fe
, u16
*strength
)
71 struct vp7045_fe_state
*state
= fe
->demodulator_priv
;
72 u16 signal
= (vp7045_read_reg(state
->d
, 0x14) << 8) |
73 vp7045_read_reg(state
->d
, 0x15);
79 static int vp7045_fe_read_snr(struct dvb_frontend
* fe
, u16
*snr
)
81 struct vp7045_fe_state
*state
= fe
->demodulator_priv
;
82 u8 _snr
= vp7045_read_reg(state
->d
, 0x09);
83 *snr
= (_snr
<< 8) | _snr
;
87 static int vp7045_fe_init(struct dvb_frontend
* fe
)
92 static int vp7045_fe_sleep(struct dvb_frontend
* fe
)
97 static int vp7045_fe_get_tune_settings(struct dvb_frontend
* fe
, struct dvb_frontend_tune_settings
*tune
)
99 tune
->min_delay_ms
= 800;
103 static int vp7045_fe_set_frontend(struct dvb_frontend
*fe
)
105 struct dtv_frontend_properties
*fep
= &fe
->dtv_property_cache
;
106 struct vp7045_fe_state
*state
= fe
->demodulator_priv
;
108 u32 freq
= fep
->frequency
/ 1000;
110 buf
[0] = (freq
>> 16) & 0xff;
111 buf
[1] = (freq
>> 8) & 0xff;
112 buf
[2] = freq
& 0xff;
115 switch (fep
->bandwidth_hz
) {
129 vp7045_usb_op(state
->d
,LOCK_TUNER_COMMAND
,buf
,5,NULL
,0,200);
133 static void vp7045_fe_release(struct dvb_frontend
* fe
)
135 struct vp7045_fe_state
*state
= fe
->demodulator_priv
;
139 static const struct dvb_frontend_ops vp7045_fe_ops
;
141 struct dvb_frontend
* vp7045_fe_attach(struct dvb_usb_device
*d
)
143 struct vp7045_fe_state
*s
= kzalloc(sizeof(struct vp7045_fe_state
), GFP_KERNEL
);
148 memcpy(&s
->fe
.ops
, &vp7045_fe_ops
, sizeof(struct dvb_frontend_ops
));
149 s
->fe
.demodulator_priv
= s
;
157 static const struct dvb_frontend_ops vp7045_fe_ops
= {
158 .delsys
= { SYS_DVBT
},
160 .name
= "Twinhan VP7045/46 USB DVB-T",
161 .frequency_min_hz
= 44250 * kHz
,
162 .frequency_max_hz
= 867250 * kHz
,
163 .frequency_stepsize_hz
= 1 * kHz
,
164 .caps
= FE_CAN_INVERSION_AUTO
|
165 FE_CAN_FEC_1_2
| FE_CAN_FEC_2_3
| FE_CAN_FEC_3_4
|
166 FE_CAN_FEC_5_6
| FE_CAN_FEC_7_8
| FE_CAN_FEC_AUTO
|
167 FE_CAN_QPSK
| FE_CAN_QAM_16
| FE_CAN_QAM_64
| FE_CAN_QAM_AUTO
|
168 FE_CAN_TRANSMISSION_MODE_AUTO
|
169 FE_CAN_GUARD_INTERVAL_AUTO
|
171 FE_CAN_HIERARCHY_AUTO
,
174 .release
= vp7045_fe_release
,
176 .init
= vp7045_fe_init
,
177 .sleep
= vp7045_fe_sleep
,
179 .set_frontend
= vp7045_fe_set_frontend
,
180 .get_tune_settings
= vp7045_fe_get_tune_settings
,
182 .read_status
= vp7045_fe_read_status
,
183 .read_ber
= vp7045_fe_read_ber
,
184 .read_signal_strength
= vp7045_fe_read_signal_strength
,
185 .read_snr
= vp7045_fe_read_snr
,
186 .read_ucblocks
= vp7045_fe_read_unc_blocks
,