blob: 5426267980c7567af09ed9646e58533e76e8df12 [file] [log] [blame]
Alan Nisota9bbe0762006-05-14 13:23:56 -03001/* DVB USB compliant Linux driver for the
Alan Nisota458b6342007-08-18 17:52:35 -03002 * - GENPIX 8pks/qpsk/DCII USB2.0 DVB-S module
Alan Nisota9bbe0762006-05-14 13:23:56 -03003 *
Alan Nisota458b6342007-08-18 17:52:35 -03004 * Copyright (C) 2006,2007 Alan Nisota (alannisota@gmail.com)
5 * Copyright (C) 2006,2007 Genpix Electronics (genpix@genpix-electronics.com)
Alan Nisota9bbe0762006-05-14 13:23:56 -03006 *
7 * Thanks to GENPIX for the sample code used to implement this module.
8 *
9 * This module is based off the vp7045 and vp702x modules
10 *
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the Free
13 * Software Foundation, version 2.
14 *
15 * see Documentation/dvb/README.dvb-usb for more information
16 */
17#include "gp8psk.h"
18
19struct gp8psk_fe_state {
20 struct dvb_frontend fe;
Alan Nisota9bbe0762006-05-14 13:23:56 -030021 struct dvb_usb_device *d;
Alan Nisota458b6342007-08-18 17:52:35 -030022 u8 lock;
Alan Nisota9bbe0762006-05-14 13:23:56 -030023 u16 snr;
Alan Nisota458b6342007-08-18 17:52:35 -030024 unsigned long next_status_check;
25 unsigned long status_check_interval;
Alan Nisota9bbe0762006-05-14 13:23:56 -030026};
27
Alan Nisota02ebf232008-12-20 12:03:06 -030028static int gp8psk_tuned_to_DCII(struct dvb_frontend *fe)
29{
30 struct gp8psk_fe_state *st = fe->demodulator_priv;
31 u8 status;
32 gp8psk_usb_in_op(st->d, GET_8PSK_CONFIG, 0, 0, &status, 1);
33 return status & bmDCtuned;
34}
35
36static int gp8psk_set_tuner_mode(struct dvb_frontend *fe, int mode)
37{
38 struct gp8psk_fe_state *state = fe->demodulator_priv;
39 return gp8psk_usb_out_op(state->d, SET_8PSK_CONFIG, mode, 0, NULL, 0);
40}
41
Alan Nisota458b6342007-08-18 17:52:35 -030042static int gp8psk_fe_update_status(struct gp8psk_fe_state *st)
43{
44 u8 buf[6];
45 if (time_after(jiffies,st->next_status_check)) {
46 gp8psk_usb_in_op(st->d, GET_SIGNAL_LOCK, 0,0,&st->lock,1);
47 gp8psk_usb_in_op(st->d, GET_SIGNAL_STRENGTH, 0,0,buf,6);
48 st->snr = (buf[1]) << 8 | buf[0];
49 st->next_status_check = jiffies + (st->status_check_interval*HZ)/1000;
50 }
51 return 0;
52}
53
Alan Nisota9bbe0762006-05-14 13:23:56 -030054static int gp8psk_fe_read_status(struct dvb_frontend* fe, fe_status_t *status)
55{
56 struct gp8psk_fe_state *st = fe->demodulator_priv;
Alan Nisota458b6342007-08-18 17:52:35 -030057 gp8psk_fe_update_status(st);
Alan Nisota9bbe0762006-05-14 13:23:56 -030058
Alan Nisota458b6342007-08-18 17:52:35 -030059 if (st->lock)
Alan Nisota9bbe0762006-05-14 13:23:56 -030060 *status = FE_HAS_LOCK | FE_HAS_SYNC | FE_HAS_VITERBI | FE_HAS_SIGNAL | FE_HAS_CARRIER;
61 else
62 *status = 0;
63
Alan Nisota458b6342007-08-18 17:52:35 -030064 if (*status & FE_HAS_LOCK)
65 st->status_check_interval = 1000;
66 else
67 st->status_check_interval = 100;
Alan Nisota9bbe0762006-05-14 13:23:56 -030068 return 0;
69}
70
71/* not supported by this Frontend */
72static int gp8psk_fe_read_ber(struct dvb_frontend* fe, u32 *ber)
73{
74 (void) fe;
75 *ber = 0;
76 return 0;
77}
78
79/* not supported by this Frontend */
80static int gp8psk_fe_read_unc_blocks(struct dvb_frontend* fe, u32 *unc)
81{
82 (void) fe;
83 *unc = 0;
84 return 0;
85}
86
87static int gp8psk_fe_read_snr(struct dvb_frontend* fe, u16 *snr)
88{
89 struct gp8psk_fe_state *st = fe->demodulator_priv;
Alan Nisota458b6342007-08-18 17:52:35 -030090 gp8psk_fe_update_status(st);
91 /* snr is reported in dBu*256 */
92 *snr = st->snr;
Alan Nisota9bbe0762006-05-14 13:23:56 -030093 return 0;
94}
95
96static int gp8psk_fe_read_signal_strength(struct dvb_frontend* fe, u16 *strength)
97{
Alan Nisota458b6342007-08-18 17:52:35 -030098 struct gp8psk_fe_state *st = fe->demodulator_priv;
99 gp8psk_fe_update_status(st);
100 /* snr is reported in dBu*256 */
101 /* snr / 38.4 ~= 100% strength */
102 /* snr * 17 returns 100% strength as 65535 */
103 if (st->snr > 0xf00)
104 *strength = 0xffff;
105 else
106 *strength = (st->snr << 4) + st->snr; /* snr*17 */
107 return 0;
Alan Nisota9bbe0762006-05-14 13:23:56 -0300108}
109
110static int gp8psk_fe_get_tune_settings(struct dvb_frontend* fe, struct dvb_frontend_tune_settings *tune)
111{
Derek Kellyfb249ca2010-10-16 16:07:47 -0300112 tune->min_delay_ms = 800;
Alan Nisota9bbe0762006-05-14 13:23:56 -0300113 return 0;
114}
115
Alan Nisota02ebf232008-12-20 12:03:06 -0300116static int gp8psk_fe_set_property(struct dvb_frontend *fe,
117 struct dtv_property *tvp)
118{
119 deb_fe("%s(..)\n", __func__);
120 return 0;
121}
122
123static int gp8psk_fe_get_property(struct dvb_frontend *fe,
124 struct dtv_property *tvp)
125{
126 deb_fe("%s(..)\n", __func__);
127 return 0;
128}
129
130
Alan Nisota9bbe0762006-05-14 13:23:56 -0300131static int gp8psk_fe_set_frontend(struct dvb_frontend* fe,
132 struct dvb_frontend_parameters *fep)
133{
134 struct gp8psk_fe_state *state = fe->demodulator_priv;
Alan Nisota02ebf232008-12-20 12:03:06 -0300135 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
Alan Nisota9bbe0762006-05-14 13:23:56 -0300136 u8 cmd[10];
137 u32 freq = fep->frequency * 1000;
Alan Nisota02ebf232008-12-20 12:03:06 -0300138 int gp_product_id = le16_to_cpu(state->d->udev->descriptor.idProduct);
139
140 deb_fe("%s()\n", __func__);
Alan Nisota9bbe0762006-05-14 13:23:56 -0300141
142 cmd[4] = freq & 0xff;
143 cmd[5] = (freq >> 8) & 0xff;
144 cmd[6] = (freq >> 16) & 0xff;
145 cmd[7] = (freq >> 24) & 0xff;
146
Andreas Oberritter8fc74fd2011-08-08 11:54:37 -0300147 /* backwards compatibility: DVB-S + 8-PSK were used for Turbo-FEC */
148 if (c->delivery_system == SYS_DVBS && c->modulation == PSK_8)
149 c->delivery_system = SYS_TURBO;
150
Alan Nisota02ebf232008-12-20 12:03:06 -0300151 switch (c->delivery_system) {
152 case SYS_DVBS:
Andreas Oberritter8fc74fd2011-08-08 11:54:37 -0300153 if (c->modulation != QPSK) {
Alan Nisota02ebf232008-12-20 12:03:06 -0300154 deb_fe("%s: unsupported modulation selected (%d)\n",
155 __func__, c->modulation);
156 return -EOPNOTSUPP;
157 }
158 c->fec_inner = FEC_AUTO;
Alan Nisota9bbe0762006-05-14 13:23:56 -0300159 break;
Andreas Oberritter8fc74fd2011-08-08 11:54:37 -0300160 case SYS_DVBS2: /* kept for backwards compatibility */
Alan Nisota02ebf232008-12-20 12:03:06 -0300161 deb_fe("%s: DVB-S2 delivery system selected\n", __func__);
162 break;
Andreas Oberritter8fc74fd2011-08-08 11:54:37 -0300163 case SYS_TURBO:
164 deb_fe("%s: Turbo-FEC delivery system selected\n", __func__);
165 break;
Alan Nisota02ebf232008-12-20 12:03:06 -0300166
Alan Nisota9bbe0762006-05-14 13:23:56 -0300167 default:
Alan Nisota02ebf232008-12-20 12:03:06 -0300168 deb_fe("%s: unsupported delivery system selected (%d)\n",
169 __func__, c->delivery_system);
170 return -EOPNOTSUPP;
Alan Nisota9bbe0762006-05-14 13:23:56 -0300171 }
172
Alan Nisota02ebf232008-12-20 12:03:06 -0300173 cmd[0] = c->symbol_rate & 0xff;
174 cmd[1] = (c->symbol_rate >> 8) & 0xff;
175 cmd[2] = (c->symbol_rate >> 16) & 0xff;
176 cmd[3] = (c->symbol_rate >> 24) & 0xff;
177 switch (c->modulation) {
178 case QPSK:
179 if (gp_product_id == USB_PID_GENPIX_8PSK_REV_1_WARM)
180 if (gp8psk_tuned_to_DCII(fe))
181 gp8psk_bcm4500_reload(state->d);
182 switch (c->fec_inner) {
183 case FEC_1_2:
184 cmd[9] = 0; break;
185 case FEC_2_3:
186 cmd[9] = 1; break;
187 case FEC_3_4:
188 cmd[9] = 2; break;
189 case FEC_5_6:
190 cmd[9] = 3; break;
191 case FEC_7_8:
192 cmd[9] = 4; break;
193 case FEC_AUTO:
194 cmd[9] = 5; break;
195 default:
196 cmd[9] = 5; break;
197 }
Andreas Oberritter8fc74fd2011-08-08 11:54:37 -0300198 if (c->delivery_system == SYS_TURBO)
199 cmd[8] = ADV_MOD_TURBO_QPSK;
200 else
201 cmd[8] = ADV_MOD_DVB_QPSK;
Alan Nisota02ebf232008-12-20 12:03:06 -0300202 break;
203 case PSK_8: /* PSK_8 is for compatibility with DN */
204 cmd[8] = ADV_MOD_TURBO_8PSK;
205 switch (c->fec_inner) {
206 case FEC_2_3:
207 cmd[9] = 0; break;
208 case FEC_3_4:
209 cmd[9] = 1; break;
210 case FEC_3_5:
211 cmd[9] = 2; break;
212 case FEC_5_6:
213 cmd[9] = 3; break;
214 case FEC_8_9:
215 cmd[9] = 4; break;
216 default:
217 cmd[9] = 0; break;
218 }
219 break;
220 case QAM_16: /* QAM_16 is for compatibility with DN */
221 cmd[8] = ADV_MOD_TURBO_16QAM;
222 cmd[9] = 0;
223 break;
224 default: /* Unknown modulation */
225 deb_fe("%s: unsupported modulation selected (%d)\n",
226 __func__, c->modulation);
227 return -EOPNOTSUPP;
228 }
229
230 if (gp_product_id == USB_PID_GENPIX_8PSK_REV_1_WARM)
231 gp8psk_set_tuner_mode(fe, 0);
232 gp8psk_usb_out_op(state->d, TUNE_8PSK, 0, 0, cmd, 10);
Alan Nisota9bbe0762006-05-14 13:23:56 -0300233
Alan Nisota458b6342007-08-18 17:52:35 -0300234 state->lock = 0;
235 state->next_status_check = jiffies;
236 state->status_check_interval = 200;
Alan Nisota9bbe0762006-05-14 13:23:56 -0300237
238 return 0;
239}
240
Alan Nisota9bbe0762006-05-14 13:23:56 -0300241static int gp8psk_fe_send_diseqc_msg (struct dvb_frontend* fe,
242 struct dvb_diseqc_master_cmd *m)
243{
244 struct gp8psk_fe_state *st = fe->demodulator_priv;
245
Harvey Harrison708bebd2008-04-08 23:20:00 -0300246 deb_fe("%s\n",__func__);
Alan Nisota9bbe0762006-05-14 13:23:56 -0300247
248 if (gp8psk_usb_out_op(st->d,SEND_DISEQC_COMMAND, m->msg[0], 0,
249 m->msg, m->msg_len)) {
250 return -EINVAL;
251 }
252 return 0;
253}
254
255static int gp8psk_fe_send_diseqc_burst (struct dvb_frontend* fe,
256 fe_sec_mini_cmd_t burst)
257{
258 struct gp8psk_fe_state *st = fe->demodulator_priv;
259 u8 cmd;
260
Harvey Harrison708bebd2008-04-08 23:20:00 -0300261 deb_fe("%s\n",__func__);
Alan Nisota9bbe0762006-05-14 13:23:56 -0300262
263 /* These commands are certainly wrong */
264 cmd = (burst == SEC_MINI_A) ? 0x00 : 0x01;
265
266 if (gp8psk_usb_out_op(st->d,SEND_DISEQC_COMMAND, cmd, 0,
267 &cmd, 0)) {
268 return -EINVAL;
269 }
270 return 0;
271}
272
273static int gp8psk_fe_set_tone (struct dvb_frontend* fe, fe_sec_tone_mode_t tone)
274{
275 struct gp8psk_fe_state* state = fe->demodulator_priv;
276
277 if (gp8psk_usb_out_op(state->d,SET_22KHZ_TONE,
278 (tone == SEC_TONE_ON), 0, NULL, 0)) {
279 return -EINVAL;
280 }
281 return 0;
282}
283
284static int gp8psk_fe_set_voltage (struct dvb_frontend* fe, fe_sec_voltage_t voltage)
285{
286 struct gp8psk_fe_state* state = fe->demodulator_priv;
287
288 if (gp8psk_usb_out_op(state->d,SET_LNB_VOLTAGE,
289 voltage == SEC_VOLTAGE_18, 0, NULL, 0)) {
290 return -EINVAL;
291 }
292 return 0;
293}
294
Alan Nisota458b6342007-08-18 17:52:35 -0300295static int gp8psk_fe_enable_high_lnb_voltage(struct dvb_frontend* fe, long onoff)
296{
297 struct gp8psk_fe_state* state = fe->demodulator_priv;
298 return gp8psk_usb_out_op(state->d, USE_EXTRA_VOLT, onoff, 0,NULL,0);
299}
300
Alan Nisota9bbe0762006-05-14 13:23:56 -0300301static int gp8psk_fe_send_legacy_dish_cmd (struct dvb_frontend* fe, unsigned long sw_cmd)
302{
303 struct gp8psk_fe_state* state = fe->demodulator_priv;
304 u8 cmd = sw_cmd & 0x7f;
305
306 if (gp8psk_usb_out_op(state->d,SET_DN_SWITCH, cmd, 0,
307 NULL, 0)) {
308 return -EINVAL;
309 }
310 if (gp8psk_usb_out_op(state->d,SET_LNB_VOLTAGE, !!(sw_cmd & 0x80),
311 0, NULL, 0)) {
312 return -EINVAL;
313 }
314
315 return 0;
316}
317
318static void gp8psk_fe_release(struct dvb_frontend* fe)
319{
320 struct gp8psk_fe_state *state = fe->demodulator_priv;
321 kfree(state);
322}
323
324static struct dvb_frontend_ops gp8psk_fe_ops;
325
326struct dvb_frontend * gp8psk_fe_attach(struct dvb_usb_device *d)
327{
328 struct gp8psk_fe_state *s = kzalloc(sizeof(struct gp8psk_fe_state), GFP_KERNEL);
329 if (s == NULL)
330 goto error;
331
332 s->d = d;
333 memcpy(&s->fe.ops, &gp8psk_fe_ops, sizeof(struct dvb_frontend_ops));
334 s->fe.demodulator_priv = s;
335
336 goto success;
337error:
338 return NULL;
339success:
340 return &s->fe;
341}
342
343
344static struct dvb_frontend_ops gp8psk_fe_ops = {
345 .info = {
Derek Kellyd12da8e2010-10-16 16:18:15 -0300346 .name = "Genpix DVB-S",
Alan Nisota9bbe0762006-05-14 13:23:56 -0300347 .type = FE_QPSK,
Alan Nisota458b6342007-08-18 17:52:35 -0300348 .frequency_min = 800000,
349 .frequency_max = 2250000,
Alan Nisota9bbe0762006-05-14 13:23:56 -0300350 .frequency_stepsize = 100,
351 .symbol_rate_min = 1000000,
352 .symbol_rate_max = 45000000,
353 .symbol_rate_tolerance = 500, /* ppm */
354 .caps = FE_CAN_INVERSION_AUTO |
Alan Nisota02ebf232008-12-20 12:03:06 -0300355 FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
356 FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO |
357 /*
358 * FE_CAN_QAM_16 is for compatibility
359 * (Myth incorrectly detects Turbo-QPSK as plain QAM-16)
360 */
Klaus Schmidingerf6a20eb2010-07-01 01:37:34 -0300361 FE_CAN_QPSK | FE_CAN_QAM_16 | FE_CAN_TURBO_FEC
Alan Nisota9bbe0762006-05-14 13:23:56 -0300362 },
363
364 .release = gp8psk_fe_release,
365
366 .init = NULL,
367 .sleep = NULL,
368
Alan Nisota02ebf232008-12-20 12:03:06 -0300369 .set_property = gp8psk_fe_set_property,
370 .get_property = gp8psk_fe_get_property,
Alan Nisota9bbe0762006-05-14 13:23:56 -0300371 .set_frontend = gp8psk_fe_set_frontend,
Alan Nisota02ebf232008-12-20 12:03:06 -0300372
Alan Nisota9bbe0762006-05-14 13:23:56 -0300373 .get_tune_settings = gp8psk_fe_get_tune_settings,
374
375 .read_status = gp8psk_fe_read_status,
376 .read_ber = gp8psk_fe_read_ber,
377 .read_signal_strength = gp8psk_fe_read_signal_strength,
378 .read_snr = gp8psk_fe_read_snr,
379 .read_ucblocks = gp8psk_fe_read_unc_blocks,
380
381 .diseqc_send_master_cmd = gp8psk_fe_send_diseqc_msg,
382 .diseqc_send_burst = gp8psk_fe_send_diseqc_burst,
383 .set_tone = gp8psk_fe_set_tone,
384 .set_voltage = gp8psk_fe_set_voltage,
385 .dishnetwork_send_legacy_command = gp8psk_fe_send_legacy_dish_cmd,
Alan Nisota458b6342007-08-18 17:52:35 -0300386 .enable_high_lnb_voltage = gp8psk_fe_enable_high_lnb_voltage
Alan Nisota9bbe0762006-05-14 13:23:56 -0300387};