1 /* DVB USB compliant Linux driver for the
2 * - GENPIX 8pks/qpsk/DCII USB2.0 DVB-S module
4 * Copyright (C) 2006,2007 Alan Nisota (alannisota@gmail.com)
5 * Copyright (C) 2006,2007 Genpix Electronics (genpix@genpix-electronics.com)
7 * Thanks to GENPIX for the sample code used to implement this module.
9 * This module is based off the vp7045 and vp702x modules
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.
15 * see Documentation/dvb/README.dvb-usb for more information
18 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
20 #include "gp8psk-fe.h"
21 #include "dvb_frontend.h"
24 module_param(debug, int, 0644);
25 MODULE_PARM_DESC(debug, "Turn on/off debugging (default:off).");
27 #define dprintk(fmt, arg...) do { \
29 printk(KERN_DEBUG pr_fmt("%s: " fmt), \
33 struct gp8psk_fe_state {
34 struct dvb_frontend fe;
36 const struct gp8psk_fe_ops *ops;
40 unsigned long next_status_check;
41 unsigned long status_check_interval;
44 static int gp8psk_tuned_to_DCII(struct dvb_frontend *fe)
46 struct gp8psk_fe_state *st = fe->demodulator_priv;
49 st->ops->in(st->priv, GET_8PSK_CONFIG, 0, 0, &status, 1);
50 return status & bmDCtuned;
53 static int gp8psk_set_tuner_mode(struct dvb_frontend *fe, int mode)
55 struct gp8psk_fe_state *st = fe->demodulator_priv;
57 return st->ops->out(st->priv, SET_8PSK_CONFIG, mode, 0, NULL, 0);
60 static int gp8psk_fe_update_status(struct gp8psk_fe_state *st)
63 if (time_after(jiffies,st->next_status_check)) {
64 st->ops->in(st->priv, GET_SIGNAL_LOCK, 0, 0, &st->lock, 1);
65 st->ops->in(st->priv, GET_SIGNAL_STRENGTH, 0, 0, buf, 6);
66 st->snr = (buf[1]) << 8 | buf[0];
67 st->next_status_check = jiffies + (st->status_check_interval*HZ)/1000;
72 static int gp8psk_fe_read_status(struct dvb_frontend *fe,
73 enum fe_status *status)
75 struct gp8psk_fe_state *st = fe->demodulator_priv;
76 gp8psk_fe_update_status(st);
79 *status = FE_HAS_LOCK | FE_HAS_SYNC | FE_HAS_VITERBI | FE_HAS_SIGNAL | FE_HAS_CARRIER;
83 if (*status & FE_HAS_LOCK)
84 st->status_check_interval = 1000;
86 st->status_check_interval = 100;
90 /* not supported by this Frontend */
91 static int gp8psk_fe_read_ber(struct dvb_frontend* fe, u32 *ber)
98 /* not supported by this Frontend */
99 static int gp8psk_fe_read_unc_blocks(struct dvb_frontend* fe, u32 *unc)
106 static int gp8psk_fe_read_snr(struct dvb_frontend* fe, u16 *snr)
108 struct gp8psk_fe_state *st = fe->demodulator_priv;
109 gp8psk_fe_update_status(st);
110 /* snr is reported in dBu*256 */
115 static int gp8psk_fe_read_signal_strength(struct dvb_frontend* fe, u16 *strength)
117 struct gp8psk_fe_state *st = fe->demodulator_priv;
118 gp8psk_fe_update_status(st);
119 /* snr is reported in dBu*256 */
120 /* snr / 38.4 ~= 100% strength */
121 /* snr * 17 returns 100% strength as 65535 */
125 *strength = (st->snr << 4) + st->snr; /* snr*17 */
129 static int gp8psk_fe_get_tune_settings(struct dvb_frontend* fe, struct dvb_frontend_tune_settings *tune)
131 tune->min_delay_ms = 800;
135 static int gp8psk_fe_set_frontend(struct dvb_frontend *fe)
137 struct gp8psk_fe_state *st = fe->demodulator_priv;
138 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
140 u32 freq = c->frequency * 1000;
142 dprintk("%s()\n", __func__);
144 cmd[4] = freq & 0xff;
145 cmd[5] = (freq >> 8) & 0xff;
146 cmd[6] = (freq >> 16) & 0xff;
147 cmd[7] = (freq >> 24) & 0xff;
149 /* backwards compatibility: DVB-S + 8-PSK were used for Turbo-FEC */
150 if (c->delivery_system == SYS_DVBS && c->modulation == PSK_8)
151 c->delivery_system = SYS_TURBO;
153 switch (c->delivery_system) {
155 if (c->modulation != QPSK) {
156 dprintk("%s: unsupported modulation selected (%d)\n",
157 __func__, c->modulation);
160 c->fec_inner = FEC_AUTO;
162 case SYS_DVBS2: /* kept for backwards compatibility */
163 dprintk("%s: DVB-S2 delivery system selected\n", __func__);
166 dprintk("%s: Turbo-FEC delivery system selected\n", __func__);
170 dprintk("%s: unsupported delivery system selected (%d)\n",
171 __func__, c->delivery_system);
175 cmd[0] = c->symbol_rate & 0xff;
176 cmd[1] = (c->symbol_rate >> 8) & 0xff;
177 cmd[2] = (c->symbol_rate >> 16) & 0xff;
178 cmd[3] = (c->symbol_rate >> 24) & 0xff;
179 switch (c->modulation) {
182 if (gp8psk_tuned_to_DCII(fe))
183 st->ops->reload(st->priv);
184 switch (c->fec_inner) {
200 if (c->delivery_system == SYS_TURBO)
201 cmd[8] = ADV_MOD_TURBO_QPSK;
203 cmd[8] = ADV_MOD_DVB_QPSK;
205 case PSK_8: /* PSK_8 is for compatibility with DN */
206 cmd[8] = ADV_MOD_TURBO_8PSK;
207 switch (c->fec_inner) {
222 case QAM_16: /* QAM_16 is for compatibility with DN */
223 cmd[8] = ADV_MOD_TURBO_16QAM;
226 default: /* Unknown modulation */
227 dprintk("%s: unsupported modulation selected (%d)\n",
228 __func__, c->modulation);
233 gp8psk_set_tuner_mode(fe, 0);
234 st->ops->out(st->priv, TUNE_8PSK, 0, 0, cmd, 10);
237 st->next_status_check = jiffies;
238 st->status_check_interval = 200;
243 static int gp8psk_fe_send_diseqc_msg (struct dvb_frontend* fe,
244 struct dvb_diseqc_master_cmd *m)
246 struct gp8psk_fe_state *st = fe->demodulator_priv;
248 dprintk("%s\n", __func__);
250 if (st->ops->out(st->priv, SEND_DISEQC_COMMAND, m->msg[0], 0,
251 m->msg, m->msg_len)) {
257 static int gp8psk_fe_send_diseqc_burst(struct dvb_frontend *fe,
258 enum fe_sec_mini_cmd burst)
260 struct gp8psk_fe_state *st = fe->demodulator_priv;
263 dprintk("%s\n", __func__);
265 /* These commands are certainly wrong */
266 cmd = (burst == SEC_MINI_A) ? 0x00 : 0x01;
268 if (st->ops->out(st->priv, SEND_DISEQC_COMMAND, cmd, 0,
275 static int gp8psk_fe_set_tone(struct dvb_frontend *fe,
276 enum fe_sec_tone_mode tone)
278 struct gp8psk_fe_state *st = fe->demodulator_priv;
280 if (st->ops->out(st->priv, SET_22KHZ_TONE,
281 (tone == SEC_TONE_ON), 0, NULL, 0)) {
287 static int gp8psk_fe_set_voltage(struct dvb_frontend *fe,
288 enum fe_sec_voltage voltage)
290 struct gp8psk_fe_state *st = fe->demodulator_priv;
292 if (st->ops->out(st->priv, SET_LNB_VOLTAGE,
293 voltage == SEC_VOLTAGE_18, 0, NULL, 0)) {
299 static int gp8psk_fe_enable_high_lnb_voltage(struct dvb_frontend* fe, long onoff)
301 struct gp8psk_fe_state *st = fe->demodulator_priv;
303 return st->ops->out(st->priv, USE_EXTRA_VOLT, onoff, 0, NULL, 0);
306 static int gp8psk_fe_send_legacy_dish_cmd (struct dvb_frontend* fe, unsigned long sw_cmd)
308 struct gp8psk_fe_state *st = fe->demodulator_priv;
309 u8 cmd = sw_cmd & 0x7f;
311 if (st->ops->out(st->priv, SET_DN_SWITCH, cmd, 0, NULL, 0))
314 if (st->ops->out(st->priv, SET_LNB_VOLTAGE, !!(sw_cmd & 0x80),
321 static void gp8psk_fe_release(struct dvb_frontend* fe)
323 struct gp8psk_fe_state *st = fe->demodulator_priv;
328 static struct dvb_frontend_ops gp8psk_fe_ops;
330 struct dvb_frontend *gp8psk_fe_attach(const struct gp8psk_fe_ops *ops,
331 void *priv, bool is_rev1)
333 struct gp8psk_fe_state *st;
335 if (!ops || !ops->in || !ops->out || !ops->reload) {
336 pr_err("Error! gp8psk-fe ops not defined.\n");
340 st = kzalloc(sizeof(struct gp8psk_fe_state), GFP_KERNEL);
344 memcpy(&st->fe.ops, &gp8psk_fe_ops, sizeof(struct dvb_frontend_ops));
345 st->fe.demodulator_priv = st;
348 st->is_rev1 = is_rev1;
350 pr_info("Frontend %sattached\n", is_rev1 ? "revision 1 " : "");
354 EXPORT_SYMBOL_GPL(gp8psk_fe_attach);
356 static struct dvb_frontend_ops gp8psk_fe_ops = {
357 .delsys = { SYS_DVBS },
359 .name = "Genpix DVB-S",
360 .frequency_min = 800000,
361 .frequency_max = 2250000,
362 .frequency_stepsize = 100,
363 .symbol_rate_min = 1000000,
364 .symbol_rate_max = 45000000,
365 .symbol_rate_tolerance = 500, /* ppm */
366 .caps = FE_CAN_INVERSION_AUTO |
367 FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
368 FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO |
370 * FE_CAN_QAM_16 is for compatibility
371 * (Myth incorrectly detects Turbo-QPSK as plain QAM-16)
373 FE_CAN_QPSK | FE_CAN_QAM_16 | FE_CAN_TURBO_FEC
376 .release = gp8psk_fe_release,
381 .set_frontend = gp8psk_fe_set_frontend,
383 .get_tune_settings = gp8psk_fe_get_tune_settings,
385 .read_status = gp8psk_fe_read_status,
386 .read_ber = gp8psk_fe_read_ber,
387 .read_signal_strength = gp8psk_fe_read_signal_strength,
388 .read_snr = gp8psk_fe_read_snr,
389 .read_ucblocks = gp8psk_fe_read_unc_blocks,
391 .diseqc_send_master_cmd = gp8psk_fe_send_diseqc_msg,
392 .diseqc_send_burst = gp8psk_fe_send_diseqc_burst,
393 .set_tone = gp8psk_fe_set_tone,
394 .set_voltage = gp8psk_fe_set_voltage,
395 .dishnetwork_send_legacy_command = gp8psk_fe_send_legacy_dish_cmd,
396 .enable_high_lnb_voltage = gp8psk_fe_enable_high_lnb_voltage