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
19 struct gp8psk_fe_state {
20 struct dvb_frontend fe;
21 struct dvb_usb_device *d;
24 unsigned long next_status_check;
25 unsigned long status_check_interval;
28 static int gp8psk_fe_update_status(struct gp8psk_fe_state *st)
31 if (time_after(jiffies,st->next_status_check)) {
32 gp8psk_usb_in_op(st->d, GET_SIGNAL_LOCK, 0,0,&st->lock,1);
33 gp8psk_usb_in_op(st->d, GET_SIGNAL_STRENGTH, 0,0,buf,6);
34 st->snr = (buf[1]) << 8 | buf[0];
35 st->next_status_check = jiffies + (st->status_check_interval*HZ)/1000;
40 static int gp8psk_fe_read_status(struct dvb_frontend* fe, fe_status_t *status)
42 struct gp8psk_fe_state *st = fe->demodulator_priv;
43 gp8psk_fe_update_status(st);
46 *status = FE_HAS_LOCK | FE_HAS_SYNC | FE_HAS_VITERBI | FE_HAS_SIGNAL | FE_HAS_CARRIER;
50 if (*status & FE_HAS_LOCK)
51 st->status_check_interval = 1000;
53 st->status_check_interval = 100;
57 /* not supported by this Frontend */
58 static int gp8psk_fe_read_ber(struct dvb_frontend* fe, u32 *ber)
65 /* not supported by this Frontend */
66 static int gp8psk_fe_read_unc_blocks(struct dvb_frontend* fe, u32 *unc)
73 static int gp8psk_fe_read_snr(struct dvb_frontend* fe, u16 *snr)
75 struct gp8psk_fe_state *st = fe->demodulator_priv;
76 gp8psk_fe_update_status(st);
77 /* snr is reported in dBu*256 */
82 static int gp8psk_fe_read_signal_strength(struct dvb_frontend* fe, u16 *strength)
84 struct gp8psk_fe_state *st = fe->demodulator_priv;
85 gp8psk_fe_update_status(st);
86 /* snr is reported in dBu*256 */
87 /* snr / 38.4 ~= 100% strength */
88 /* snr * 17 returns 100% strength as 65535 */
92 *strength = (st->snr << 4) + st->snr; /* snr*17 */
96 static int gp8psk_fe_get_tune_settings(struct dvb_frontend* fe, struct dvb_frontend_tune_settings *tune)
98 tune->min_delay_ms = 200;
102 static int gp8psk_fe_set_frontend(struct dvb_frontend* fe,
103 struct dvb_frontend_parameters *fep)
105 struct gp8psk_fe_state *state = fe->demodulator_priv;
107 u32 freq = fep->frequency * 1000;
109 cmd[4] = freq & 0xff;
110 cmd[5] = (freq >> 8) & 0xff;
111 cmd[6] = (freq >> 16) & 0xff;
112 cmd[7] = (freq >> 24) & 0xff;
114 switch(fe->ops.info.type) {
116 cmd[0] = fep->u.qpsk.symbol_rate & 0xff;
117 cmd[1] = (fep->u.qpsk.symbol_rate >> 8) & 0xff;
118 cmd[2] = (fep->u.qpsk.symbol_rate >> 16) & 0xff;
119 cmd[3] = (fep->u.qpsk.symbol_rate >> 24) & 0xff;
120 cmd[8] = ADV_MOD_DVB_QPSK;
121 cmd[9] = 0x03; /*ADV_MOD_FEC_XXX*/
124 // other modes are unsuported right now
134 gp8psk_usb_out_op(state->d,TUNE_8PSK,0,0,cmd,10);
137 state->next_status_check = jiffies;
138 state->status_check_interval = 200;
143 static int gp8psk_fe_get_frontend(struct dvb_frontend* fe,
144 struct dvb_frontend_parameters *fep)
150 static int gp8psk_fe_send_diseqc_msg (struct dvb_frontend* fe,
151 struct dvb_diseqc_master_cmd *m)
153 struct gp8psk_fe_state *st = fe->demodulator_priv;
155 deb_fe("%s\n",__FUNCTION__);
157 if (gp8psk_usb_out_op(st->d,SEND_DISEQC_COMMAND, m->msg[0], 0,
158 m->msg, m->msg_len)) {
164 static int gp8psk_fe_send_diseqc_burst (struct dvb_frontend* fe,
165 fe_sec_mini_cmd_t burst)
167 struct gp8psk_fe_state *st = fe->demodulator_priv;
170 deb_fe("%s\n",__FUNCTION__);
172 /* These commands are certainly wrong */
173 cmd = (burst == SEC_MINI_A) ? 0x00 : 0x01;
175 if (gp8psk_usb_out_op(st->d,SEND_DISEQC_COMMAND, cmd, 0,
182 static int gp8psk_fe_set_tone (struct dvb_frontend* fe, fe_sec_tone_mode_t tone)
184 struct gp8psk_fe_state* state = fe->demodulator_priv;
186 if (gp8psk_usb_out_op(state->d,SET_22KHZ_TONE,
187 (tone == SEC_TONE_ON), 0, NULL, 0)) {
193 static int gp8psk_fe_set_voltage (struct dvb_frontend* fe, fe_sec_voltage_t voltage)
195 struct gp8psk_fe_state* state = fe->demodulator_priv;
197 if (gp8psk_usb_out_op(state->d,SET_LNB_VOLTAGE,
198 voltage == SEC_VOLTAGE_18, 0, NULL, 0)) {
204 static int gp8psk_fe_enable_high_lnb_voltage(struct dvb_frontend* fe, long onoff)
206 struct gp8psk_fe_state* state = fe->demodulator_priv;
207 return gp8psk_usb_out_op(state->d, USE_EXTRA_VOLT, onoff, 0,NULL,0);
210 static int gp8psk_fe_send_legacy_dish_cmd (struct dvb_frontend* fe, unsigned long sw_cmd)
212 struct gp8psk_fe_state* state = fe->demodulator_priv;
213 u8 cmd = sw_cmd & 0x7f;
215 if (gp8psk_usb_out_op(state->d,SET_DN_SWITCH, cmd, 0,
219 if (gp8psk_usb_out_op(state->d,SET_LNB_VOLTAGE, !!(sw_cmd & 0x80),
227 static void gp8psk_fe_release(struct dvb_frontend* fe)
229 struct gp8psk_fe_state *state = fe->demodulator_priv;
233 static struct dvb_frontend_ops gp8psk_fe_ops;
235 struct dvb_frontend * gp8psk_fe_attach(struct dvb_usb_device *d)
237 struct gp8psk_fe_state *s = kzalloc(sizeof(struct gp8psk_fe_state), GFP_KERNEL);
242 memcpy(&s->fe.ops, &gp8psk_fe_ops, sizeof(struct dvb_frontend_ops));
243 s->fe.demodulator_priv = s;
253 static struct dvb_frontend_ops gp8psk_fe_ops = {
255 .name = "Genpix 8psk-to-USB2 DVB-S",
257 .frequency_min = 800000,
258 .frequency_max = 2250000,
259 .frequency_stepsize = 100,
260 .symbol_rate_min = 1000000,
261 .symbol_rate_max = 45000000,
262 .symbol_rate_tolerance = 500, /* ppm */
263 .caps = FE_CAN_INVERSION_AUTO |
264 FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
265 FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO |
269 .release = gp8psk_fe_release,
274 .set_frontend = gp8psk_fe_set_frontend,
275 .get_frontend = gp8psk_fe_get_frontend,
276 .get_tune_settings = gp8psk_fe_get_tune_settings,
278 .read_status = gp8psk_fe_read_status,
279 .read_ber = gp8psk_fe_read_ber,
280 .read_signal_strength = gp8psk_fe_read_signal_strength,
281 .read_snr = gp8psk_fe_read_snr,
282 .read_ucblocks = gp8psk_fe_read_unc_blocks,
284 .diseqc_send_master_cmd = gp8psk_fe_send_diseqc_msg,
285 .diseqc_send_burst = gp8psk_fe_send_diseqc_burst,
286 .set_tone = gp8psk_fe_set_tone,
287 .set_voltage = gp8psk_fe_set_voltage,
288 .dishnetwork_send_legacy_command = gp8psk_fe_send_legacy_dish_cmd,
289 .enable_high_lnb_voltage = gp8psk_fe_enable_high_lnb_voltage