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;
22 unsigned char data[80];
23 struct mutex data_mutex;
26 static int dtt200u_fe_read_status(struct dvb_frontend *fe,
29 struct dtt200u_fe_state *state = fe->demodulator_priv;
32 mutex_lock(&state->data_mutex);
33 state->data[0] = GET_TUNE_STATUS;
35 ret = dvb_usb_generic_rw(state->d, state->data, 1, state->data, 3, 0);
38 mutex_unlock(&state->data_mutex);
42 switch (state->data[0]) {
44 *stat = FE_HAS_SIGNAL | FE_HAS_CARRIER |
45 FE_HAS_VITERBI | FE_HAS_SYNC | FE_HAS_LOCK;
47 case 0x00: /* pending */
48 *stat = FE_TIMEDOUT; /* during set_frontend */
51 case 0x02: /* failed */
55 mutex_unlock(&state->data_mutex);
59 static int dtt200u_fe_read_ber(struct dvb_frontend* fe, u32 *ber)
61 struct dtt200u_fe_state *state = fe->demodulator_priv;
64 mutex_lock(&state->data_mutex);
65 state->data[0] = GET_VIT_ERR_CNT;
67 ret = dvb_usb_generic_rw(state->d, state->data, 1, state->data, 3, 0);
69 *ber = (state->data[0] << 16) | (state->data[1] << 8) | state->data[2];
71 mutex_unlock(&state->data_mutex);
75 static int dtt200u_fe_read_unc_blocks(struct dvb_frontend* fe, u32 *unc)
77 struct dtt200u_fe_state *state = fe->demodulator_priv;
80 mutex_lock(&state->data_mutex);
81 state->data[0] = GET_RS_UNCOR_BLK_CNT;
83 ret = dvb_usb_generic_rw(state->d, state->data, 1, state->data, 2, 0);
85 *unc = (state->data[0] << 8) | state->data[1];
87 mutex_unlock(&state->data_mutex);
91 static int dtt200u_fe_read_signal_strength(struct dvb_frontend* fe, u16 *strength)
93 struct dtt200u_fe_state *state = fe->demodulator_priv;
96 mutex_lock(&state->data_mutex);
97 state->data[0] = GET_AGC;
99 ret = dvb_usb_generic_rw(state->d, state->data, 1, state->data, 1, 0);
101 *strength = (state->data[0] << 8) | state->data[0];
103 mutex_unlock(&state->data_mutex);
107 static int dtt200u_fe_read_snr(struct dvb_frontend* fe, u16 *snr)
109 struct dtt200u_fe_state *state = fe->demodulator_priv;
112 mutex_lock(&state->data_mutex);
113 state->data[0] = GET_SNR;
115 ret = dvb_usb_generic_rw(state->d, state->data, 1, state->data, 1, 0);
117 *snr = ~((state->data[0] << 8) | state->data[0]);
119 mutex_unlock(&state->data_mutex);
123 static int dtt200u_fe_init(struct dvb_frontend* fe)
125 struct dtt200u_fe_state *state = fe->demodulator_priv;
128 mutex_lock(&state->data_mutex);
129 state->data[0] = SET_INIT;
131 ret = dvb_usb_generic_write(state->d, state->data, 1);
132 mutex_unlock(&state->data_mutex);
137 static int dtt200u_fe_sleep(struct dvb_frontend* fe)
139 return dtt200u_fe_init(fe);
142 static int dtt200u_fe_get_tune_settings(struct dvb_frontend* fe, struct dvb_frontend_tune_settings *tune)
144 tune->min_delay_ms = 1500;
150 static int dtt200u_fe_set_frontend(struct dvb_frontend *fe)
152 struct dtv_frontend_properties *fep = &fe->dtv_property_cache;
153 struct dtt200u_fe_state *state = fe->demodulator_priv;
155 u16 freq = fep->frequency / 250000;
157 mutex_lock(&state->data_mutex);
158 state->data[0] = SET_BANDWIDTH;
159 switch (fep->bandwidth_hz) {
174 ret = dvb_usb_generic_write(state->d, state->data, 2);
178 state->data[0] = SET_RF_FREQ;
179 state->data[1] = freq & 0xff;
180 state->data[2] = (freq >> 8) & 0xff;
181 ret = dvb_usb_generic_write(state->d, state->data, 3);
186 mutex_unlock(&state->data_mutex);
190 static int dtt200u_fe_get_frontend(struct dvb_frontend* fe,
191 struct dtv_frontend_properties *fep)
193 struct dtt200u_fe_state *state = fe->demodulator_priv;
195 memcpy(fep, &state->fep, sizeof(struct dtv_frontend_properties));
199 static void dtt200u_fe_release(struct dvb_frontend* fe)
201 struct dtt200u_fe_state *state = (struct dtt200u_fe_state*) fe->demodulator_priv;
205 static struct dvb_frontend_ops dtt200u_fe_ops;
207 struct dvb_frontend* dtt200u_fe_attach(struct dvb_usb_device *d)
209 struct dtt200u_fe_state* state = NULL;
211 /* allocate memory for the internal state */
212 state = kzalloc(sizeof(struct dtt200u_fe_state), GFP_KERNEL);
216 deb_info("attaching frontend dtt200u\n");
219 mutex_init(&state->data_mutex);
221 memcpy(&state->frontend.ops,&dtt200u_fe_ops,sizeof(struct dvb_frontend_ops));
222 state->frontend.demodulator_priv = state;
224 return &state->frontend;
229 static struct dvb_frontend_ops dtt200u_fe_ops = {
230 .delsys = { SYS_DVBT },
232 .name = "WideView USB DVB-T",
233 .frequency_min = 44250000,
234 .frequency_max = 867250000,
235 .frequency_stepsize = 250000,
236 .caps = FE_CAN_INVERSION_AUTO |
237 FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
238 FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO |
239 FE_CAN_QPSK | FE_CAN_QAM_16 | FE_CAN_QAM_64 | FE_CAN_QAM_AUTO |
240 FE_CAN_TRANSMISSION_MODE_AUTO |
241 FE_CAN_GUARD_INTERVAL_AUTO |
243 FE_CAN_HIERARCHY_AUTO,
246 .release = dtt200u_fe_release,
248 .init = dtt200u_fe_init,
249 .sleep = dtt200u_fe_sleep,
251 .set_frontend = dtt200u_fe_set_frontend,
252 .get_frontend = dtt200u_fe_get_frontend,
253 .get_tune_settings = dtt200u_fe_get_tune_settings,
255 .read_status = dtt200u_fe_read_status,
256 .read_ber = dtt200u_fe_read_ber,
257 .read_signal_strength = dtt200u_fe_read_signal_strength,
258 .read_snr = dtt200u_fe_read_snr,
259 .read_ucblocks = dtt200u_fe_read_unc_blocks,