1
/* DVB frontend part of the Linux driver for the TwinhanDTV StarBox USB2.0
4
* Copyright (C) 2005 Ralph Metzler <rjkm@metzlerbros.de>
5
* Metzler Brothers Systementwicklung GbR
7
* Copyright (C) 2005 Patrick Boettcher <patrick.boettcher@desy.de>
9
* Thanks to Twinhan who kindly provided hardware and information.
11
* This file can be removed soon, after the DST-driver is rewritten to provice
12
* the frontend-controlling separately.
14
* This program is free software; you can redistribute it and/or modify it
15
* under the terms of the GNU General Public License as published by the Free
16
* Software Foundation, version 2.
18
* see Documentation/dvb/README.dvb-usb for more information
23
struct vp702x_fe_state {
24
struct dvb_frontend fe;
25
struct dvb_usb_device *d;
27
struct dvb_frontend_ops ops;
29
fe_sec_voltage_t voltage;
30
fe_sec_tone_mode_t tone_mode;
38
unsigned long next_status_check;
39
unsigned long status_check_interval;
42
static int vp702x_fe_refresh_state(struct vp702x_fe_state *st)
44
struct vp702x_device_state *dst = st->d->priv;
47
if (time_after(jiffies, st->next_status_check)) {
48
mutex_lock(&dst->buf_mutex);
51
vp702x_usb_in_op(st->d, READ_STATUS, 0, 0, buf, 10);
54
vp702x_usb_in_op(st->d, READ_TUNER_REG_REQ, 0x11, 0, buf, 1);
57
vp702x_usb_in_op(st->d, READ_TUNER_REG_REQ, 0x15, 0, buf, 1);
60
mutex_unlock(&dst->buf_mutex);
61
st->next_status_check = jiffies + (st->status_check_interval*HZ)/1000;
66
static u8 vp702x_chksum(u8 *buf,int f, int count)
70
for (i = f; i < f+count; i++)
75
static int vp702x_fe_read_status(struct dvb_frontend* fe, fe_status_t *status)
77
struct vp702x_fe_state *st = fe->demodulator_priv;
78
vp702x_fe_refresh_state(st);
79
deb_fe("%s\n",__func__);
82
*status = FE_HAS_LOCK | FE_HAS_SYNC | FE_HAS_VITERBI | FE_HAS_SIGNAL | FE_HAS_CARRIER;
86
if (*status & FE_HAS_LOCK)
87
st->status_check_interval = 1000;
89
st->status_check_interval = 250;
93
/* not supported by this Frontend */
94
static int vp702x_fe_read_ber(struct dvb_frontend* fe, u32 *ber)
96
struct vp702x_fe_state *st = fe->demodulator_priv;
97
vp702x_fe_refresh_state(st);
102
/* not supported by this Frontend */
103
static int vp702x_fe_read_unc_blocks(struct dvb_frontend* fe, u32 *unc)
105
struct vp702x_fe_state *st = fe->demodulator_priv;
106
vp702x_fe_refresh_state(st);
111
static int vp702x_fe_read_signal_strength(struct dvb_frontend* fe, u16 *strength)
113
struct vp702x_fe_state *st = fe->demodulator_priv;
114
vp702x_fe_refresh_state(st);
116
*strength = (st->sig << 8) | st->sig;
120
static int vp702x_fe_read_snr(struct dvb_frontend* fe, u16 *snr)
123
struct vp702x_fe_state *st = fe->demodulator_priv;
124
vp702x_fe_refresh_state(st);
126
_snr = (st->snr & 0x1f) * 0xff / 0x1f;
127
*snr = (_snr << 8) | _snr;
131
static int vp702x_fe_get_tune_settings(struct dvb_frontend* fe, struct dvb_frontend_tune_settings *tune)
133
deb_fe("%s\n",__func__);
134
tune->min_delay_ms = 2000;
138
static int vp702x_fe_set_frontend(struct dvb_frontend* fe,
139
struct dvb_frontend_parameters *fep)
141
struct vp702x_fe_state *st = fe->demodulator_priv;
142
struct vp702x_device_state *dst = st->d->priv;
143
u32 freq = fep->frequency/1000;
145
/* u16 frequencyRef[16] = { 2, 4, 8, 16, 32, 64, 128, 256, 24, 5, 10, 20, 40, 80, 160, 320 }; */
149
mutex_lock(&dst->buf_mutex);
154
cmd[0] = (freq >> 8) & 0x7f;
155
cmd[1] = freq & 0xff;
156
cmd[2] = 1; /* divrate == 4 -> frequencyRef[1] -> 1 here */
158
sr = (u64) (fep->u.qpsk.symbol_rate/1000) << 20;
160
cmd[3] = (sr >> 12) & 0xff;
161
cmd[4] = (sr >> 4) & 0xff;
162
cmd[5] = (sr << 4) & 0xf0;
164
deb_fe("setting frontend to: %u -> %u (%x) LNB-based GHz, symbolrate: %d -> %lu (%lx)\n",
165
fep->frequency,freq,freq, fep->u.qpsk.symbol_rate,
166
(unsigned long) sr, (unsigned long) sr);
168
/* if (fep->inversion == INVERSION_ON)
171
if (st->voltage == SEC_VOLTAGE_18)
174
/* if (fep->u.qpsk.symbol_rate > 8000000)
177
if (fep->frequency < 1531000)
180
if (st->tone_mode == SEC_TONE_ON)
183
cmd[7] = vp702x_chksum(cmd,0,7);
185
st->status_check_interval = 250;
186
st->next_status_check = jiffies;
188
vp702x_usb_inout_op(st->d, cmd, 8, cmd, 10, 100);
190
if (cmd[2] == 0 && cmd[3] == 0)
191
deb_fe("tuning failed.\n");
193
deb_fe("tuning succeeded.\n");
195
mutex_unlock(&dst->buf_mutex);
200
static int vp702x_fe_init(struct dvb_frontend *fe)
202
struct vp702x_fe_state *st = fe->demodulator_priv;
203
deb_fe("%s\n",__func__);
204
vp702x_usb_in_op(st->d, RESET_TUNER, 0, 0, NULL, 0);
208
static int vp702x_fe_sleep(struct dvb_frontend *fe)
210
deb_fe("%s\n",__func__);
214
static int vp702x_fe_get_frontend(struct dvb_frontend* fe,
215
struct dvb_frontend_parameters *fep)
217
deb_fe("%s\n",__func__);
221
static int vp702x_fe_send_diseqc_msg (struct dvb_frontend* fe,
222
struct dvb_diseqc_master_cmd *m)
225
struct vp702x_fe_state *st = fe->demodulator_priv;
226
struct vp702x_device_state *dst = st->d->priv;
228
deb_fe("%s\n",__func__);
233
mutex_lock(&dst->buf_mutex);
236
cmd[1] = SET_DISEQC_CMD;
238
memcpy(&cmd[3], m->msg, m->msg_len);
239
cmd[7] = vp702x_chksum(cmd, 0, 7);
241
vp702x_usb_inout_op(st->d, cmd, 8, cmd, 10, 100);
243
if (cmd[2] == 0 && cmd[3] == 0)
244
deb_fe("diseqc cmd failed.\n");
246
deb_fe("diseqc cmd succeeded.\n");
248
mutex_unlock(&dst->buf_mutex);
253
static int vp702x_fe_send_diseqc_burst (struct dvb_frontend* fe, fe_sec_mini_cmd_t burst)
255
deb_fe("%s\n",__func__);
259
static int vp702x_fe_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t tone)
261
struct vp702x_fe_state *st = fe->demodulator_priv;
262
struct vp702x_device_state *dst = st->d->priv;
265
deb_fe("%s\n",__func__);
267
st->tone_mode = tone;
269
if (tone == SEC_TONE_ON)
270
st->lnb_buf[2] = 0x02;
272
st->lnb_buf[2] = 0x00;
274
st->lnb_buf[7] = vp702x_chksum(st->lnb_buf, 0, 7);
276
mutex_lock(&dst->buf_mutex);
279
memcpy(buf, st->lnb_buf, 8);
281
vp702x_usb_inout_op(st->d, buf, 8, buf, 10, 100);
282
if (buf[2] == 0 && buf[3] == 0)
283
deb_fe("set_tone cmd failed.\n");
285
deb_fe("set_tone cmd succeeded.\n");
287
mutex_unlock(&dst->buf_mutex);
292
static int vp702x_fe_set_voltage (struct dvb_frontend* fe, fe_sec_voltage_t
295
struct vp702x_fe_state *st = fe->demodulator_priv;
296
struct vp702x_device_state *dst = st->d->priv;
298
deb_fe("%s\n",__func__);
300
st->voltage = voltage;
302
if (voltage != SEC_VOLTAGE_OFF)
303
st->lnb_buf[4] = 0x01;
305
st->lnb_buf[4] = 0x00;
307
st->lnb_buf[7] = vp702x_chksum(st->lnb_buf, 0, 7);
309
mutex_lock(&dst->buf_mutex);
312
memcpy(buf, st->lnb_buf, 8);
314
vp702x_usb_inout_op(st->d, buf, 8, buf, 10, 100);
315
if (buf[2] == 0 && buf[3] == 0)
316
deb_fe("set_voltage cmd failed.\n");
318
deb_fe("set_voltage cmd succeeded.\n");
320
mutex_unlock(&dst->buf_mutex);
324
static void vp702x_fe_release(struct dvb_frontend* fe)
326
struct vp702x_fe_state *st = fe->demodulator_priv;
330
static struct dvb_frontend_ops vp702x_fe_ops;
332
struct dvb_frontend * vp702x_fe_attach(struct dvb_usb_device *d)
334
struct vp702x_fe_state *s = kzalloc(sizeof(struct vp702x_fe_state), GFP_KERNEL);
340
memcpy(&s->fe.ops,&vp702x_fe_ops,sizeof(struct dvb_frontend_ops));
341
s->fe.demodulator_priv = s;
343
s->lnb_buf[1] = SET_LNB_POWER;
344
s->lnb_buf[3] = 0xff; /* 0=tone burst, 2=data burst, ff=off */
352
static struct dvb_frontend_ops vp702x_fe_ops = {
354
.name = "Twinhan DST-like frontend (VP7021/VP7020) DVB-S",
356
.frequency_min = 950000,
357
.frequency_max = 2150000,
358
.frequency_stepsize = 1000, /* kHz for QPSK frontends */
359
.frequency_tolerance = 0,
360
.symbol_rate_min = 1000000,
361
.symbol_rate_max = 45000000,
362
.symbol_rate_tolerance = 500, /* ppm */
363
.caps = FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
364
FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 |
368
.release = vp702x_fe_release,
370
.init = vp702x_fe_init,
371
.sleep = vp702x_fe_sleep,
373
.set_frontend = vp702x_fe_set_frontend,
374
.get_frontend = vp702x_fe_get_frontend,
375
.get_tune_settings = vp702x_fe_get_tune_settings,
377
.read_status = vp702x_fe_read_status,
378
.read_ber = vp702x_fe_read_ber,
379
.read_signal_strength = vp702x_fe_read_signal_strength,
380
.read_snr = vp702x_fe_read_snr,
381
.read_ucblocks = vp702x_fe_read_unc_blocks,
383
.diseqc_send_master_cmd = vp702x_fe_send_diseqc_msg,
384
.diseqc_send_burst = vp702x_fe_send_diseqc_burst,
385
.set_tone = vp702x_fe_set_tone,
386
.set_voltage = vp702x_fe_set_voltage,