Initial commit
[wrt350n-kernel.git] / drivers / media / dvb / dvb-usb / gp8psk-fe.c
blobe37142d9271a83aa0f1b3e3575e21dc3c5a8a6f3
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
17 #include "gp8psk.h"
19 struct gp8psk_fe_state {
20 struct dvb_frontend fe;
21 struct dvb_usb_device *d;
22 u8 lock;
23 u16 snr;
24 unsigned long next_status_check;
25 unsigned long status_check_interval;
28 static int gp8psk_fe_update_status(struct gp8psk_fe_state *st)
30 u8 buf[6];
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;
37 return 0;
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);
45 if (st->lock)
46 *status = FE_HAS_LOCK | FE_HAS_SYNC | FE_HAS_VITERBI | FE_HAS_SIGNAL | FE_HAS_CARRIER;
47 else
48 *status = 0;
50 if (*status & FE_HAS_LOCK)
51 st->status_check_interval = 1000;
52 else
53 st->status_check_interval = 100;
54 return 0;
57 /* not supported by this Frontend */
58 static int gp8psk_fe_read_ber(struct dvb_frontend* fe, u32 *ber)
60 (void) fe;
61 *ber = 0;
62 return 0;
65 /* not supported by this Frontend */
66 static int gp8psk_fe_read_unc_blocks(struct dvb_frontend* fe, u32 *unc)
68 (void) fe;
69 *unc = 0;
70 return 0;
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 */
78 *snr = st->snr;
79 return 0;
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 */
89 if (st->snr > 0xf00)
90 *strength = 0xffff;
91 else
92 *strength = (st->snr << 4) + st->snr; /* snr*17 */
93 return 0;
96 static int gp8psk_fe_get_tune_settings(struct dvb_frontend* fe, struct dvb_frontend_tune_settings *tune)
98 tune->min_delay_ms = 200;
99 return 0;
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;
106 u8 cmd[10];
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) {
115 case FE_QPSK:
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*/
122 break;
123 default:
124 // other modes are unsuported right now
125 cmd[0] = 0;
126 cmd[1] = 0;
127 cmd[2] = 0;
128 cmd[3] = 0;
129 cmd[8] = 0;
130 cmd[9] = 0;
131 break;
134 gp8psk_usb_out_op(state->d,TUNE_8PSK,0,0,cmd,10);
136 state->lock = 0;
137 state->next_status_check = jiffies;
138 state->status_check_interval = 200;
140 return 0;
143 static int gp8psk_fe_get_frontend(struct dvb_frontend* fe,
144 struct dvb_frontend_parameters *fep)
146 return 0;
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)) {
159 return -EINVAL;
161 return 0;
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;
168 u8 cmd;
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,
176 &cmd, 0)) {
177 return -EINVAL;
179 return 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)) {
188 return -EINVAL;
190 return 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)) {
199 return -EINVAL;
201 return 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,
216 NULL, 0)) {
217 return -EINVAL;
219 if (gp8psk_usb_out_op(state->d,SET_LNB_VOLTAGE, !!(sw_cmd & 0x80),
220 0, NULL, 0)) {
221 return -EINVAL;
224 return 0;
227 static void gp8psk_fe_release(struct dvb_frontend* fe)
229 struct gp8psk_fe_state *state = fe->demodulator_priv;
230 kfree(state);
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);
238 if (s == NULL)
239 goto error;
241 s->d = d;
242 memcpy(&s->fe.ops, &gp8psk_fe_ops, sizeof(struct dvb_frontend_ops));
243 s->fe.demodulator_priv = s;
245 goto success;
246 error:
247 return NULL;
248 success:
249 return &s->fe;
253 static struct dvb_frontend_ops gp8psk_fe_ops = {
254 .info = {
255 .name = "Genpix 8psk-to-USB2 DVB-S",
256 .type = FE_QPSK,
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 |
266 FE_CAN_QPSK
269 .release = gp8psk_fe_release,
271 .init = NULL,
272 .sleep = NULL,
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