1 /* Frontend part of the Linux driver for the WideView/ Yakumo/ Hama/
2 * Typhoon/ Yuan DVB-T USB2.0 receiver.
4 * Copyright (C) 2005 Patrick Boettcher <patrick.boettcher@posteo.de>
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation, version 2.
10 * see Documentation/dvb/README.dvb-usb for more information
14 struct dtt200u_fe_state
{
15 struct dvb_usb_device
*d
;
19 struct dtv_frontend_properties fep
;
20 struct dvb_frontend frontend
;
23 static int dtt200u_fe_read_status(struct dvb_frontend
*fe
,
26 struct dtt200u_fe_state
*state
= fe
->demodulator_priv
;
27 u8 st
= GET_TUNE_STATUS
, b
[3];
29 dvb_usb_generic_rw(state
->d
,&st
,1,b
,3,0);
33 *stat
= FE_HAS_SIGNAL
| FE_HAS_CARRIER
|
34 FE_HAS_VITERBI
| FE_HAS_SYNC
| FE_HAS_LOCK
;
36 case 0x00: /* pending */
37 *stat
= FE_TIMEDOUT
; /* during set_frontend */
40 case 0x02: /* failed */
47 static int dtt200u_fe_read_ber(struct dvb_frontend
* fe
, u32
*ber
)
49 struct dtt200u_fe_state
*state
= fe
->demodulator_priv
;
50 u8 bw
= GET_VIT_ERR_CNT
,b
[3];
51 dvb_usb_generic_rw(state
->d
,&bw
,1,b
,3,0);
52 *ber
= (b
[0] << 16) | (b
[1] << 8) | b
[2];
56 static int dtt200u_fe_read_unc_blocks(struct dvb_frontend
* fe
, u32
*unc
)
58 struct dtt200u_fe_state
*state
= fe
->demodulator_priv
;
59 u8 bw
= GET_RS_UNCOR_BLK_CNT
,b
[2];
61 dvb_usb_generic_rw(state
->d
,&bw
,1,b
,2,0);
62 *unc
= (b
[0] << 8) | b
[1];
66 static int dtt200u_fe_read_signal_strength(struct dvb_frontend
* fe
, u16
*strength
)
68 struct dtt200u_fe_state
*state
= fe
->demodulator_priv
;
70 dvb_usb_generic_rw(state
->d
,&bw
,1,&b
,1,0);
71 *strength
= (b
<< 8) | b
;
75 static int dtt200u_fe_read_snr(struct dvb_frontend
* fe
, u16
*snr
)
77 struct dtt200u_fe_state
*state
= fe
->demodulator_priv
;
79 dvb_usb_generic_rw(state
->d
,&bw
,1,&br
,1,0);
80 *snr
= ~((br
<< 8) | br
);
84 static int dtt200u_fe_init(struct dvb_frontend
* fe
)
86 struct dtt200u_fe_state
*state
= fe
->demodulator_priv
;
88 return dvb_usb_generic_write(state
->d
,&b
,1);
91 static int dtt200u_fe_sleep(struct dvb_frontend
* fe
)
93 return dtt200u_fe_init(fe
);
96 static int dtt200u_fe_get_tune_settings(struct dvb_frontend
* fe
, struct dvb_frontend_tune_settings
*tune
)
98 tune
->min_delay_ms
= 1500;
104 static int dtt200u_fe_set_frontend(struct dvb_frontend
*fe
)
106 struct dtv_frontend_properties
*fep
= &fe
->dtv_property_cache
;
107 struct dtt200u_fe_state
*state
= fe
->demodulator_priv
;
110 u16 freq
= fep
->frequency
/ 250000;
111 u8 bwbuf
[2] = { SET_BANDWIDTH
, 0 },freqbuf
[3] = { SET_RF_FREQ
, 0, 0 };
113 switch (fep
->bandwidth_hz
) {
127 dvb_usb_generic_write(state
->d
,bwbuf
,2);
129 freqbuf
[1] = freq
& 0xff;
130 freqbuf
[2] = (freq
>> 8) & 0xff;
131 dvb_usb_generic_write(state
->d
,freqbuf
,3);
133 for (i
= 0; i
< 30; i
++) {
135 dtt200u_fe_read_status(fe
, &st
);
136 if (st
& FE_TIMEDOUT
)
143 static int dtt200u_fe_get_frontend(struct dvb_frontend
* fe
,
144 struct dtv_frontend_properties
*fep
)
146 struct dtt200u_fe_state
*state
= fe
->demodulator_priv
;
148 memcpy(fep
, &state
->fep
, sizeof(struct dtv_frontend_properties
));
152 static void dtt200u_fe_release(struct dvb_frontend
* fe
)
154 struct dtt200u_fe_state
*state
= (struct dtt200u_fe_state
*) fe
->demodulator_priv
;
158 static struct dvb_frontend_ops dtt200u_fe_ops
;
160 struct dvb_frontend
* dtt200u_fe_attach(struct dvb_usb_device
*d
)
162 struct dtt200u_fe_state
* state
= NULL
;
164 /* allocate memory for the internal state */
165 state
= kzalloc(sizeof(struct dtt200u_fe_state
), GFP_KERNEL
);
169 deb_info("attaching frontend dtt200u\n");
173 memcpy(&state
->frontend
.ops
,&dtt200u_fe_ops
,sizeof(struct dvb_frontend_ops
));
174 state
->frontend
.demodulator_priv
= state
;
176 return &state
->frontend
;
181 static struct dvb_frontend_ops dtt200u_fe_ops
= {
182 .delsys
= { SYS_DVBT
},
184 .name
= "WideView USB DVB-T",
185 .frequency_min
= 44250000,
186 .frequency_max
= 867250000,
187 .frequency_stepsize
= 250000,
188 .caps
= FE_CAN_INVERSION_AUTO
|
189 FE_CAN_FEC_1_2
| FE_CAN_FEC_2_3
| FE_CAN_FEC_3_4
|
190 FE_CAN_FEC_5_6
| FE_CAN_FEC_7_8
| FE_CAN_FEC_AUTO
|
191 FE_CAN_QPSK
| FE_CAN_QAM_16
| FE_CAN_QAM_64
| FE_CAN_QAM_AUTO
|
192 FE_CAN_TRANSMISSION_MODE_AUTO
|
193 FE_CAN_GUARD_INTERVAL_AUTO
|
195 FE_CAN_HIERARCHY_AUTO
,
198 .release
= dtt200u_fe_release
,
200 .init
= dtt200u_fe_init
,
201 .sleep
= dtt200u_fe_sleep
,
203 .set_frontend
= dtt200u_fe_set_frontend
,
204 .get_frontend
= dtt200u_fe_get_frontend
,
205 .get_tune_settings
= dtt200u_fe_get_tune_settings
,
207 .read_status
= dtt200u_fe_read_status
,
208 .read_ber
= dtt200u_fe_read_ber
,
209 .read_signal_strength
= dtt200u_fe_read_signal_strength
,
210 .read_snr
= dtt200u_fe_read_snr
,
211 .read_ucblocks
= dtt200u_fe_read_unc_blocks
,