2 * Frontend driver for the 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.
16 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
18 #include "gp8psk-fe.h"
19 #include <media/dvb_frontend.h>
22 module_param(debug
, int, 0644);
23 MODULE_PARM_DESC(debug
, "Turn on/off debugging (default:off).");
25 #define dprintk(fmt, arg...) do { \
27 printk(KERN_DEBUG pr_fmt("%s: " fmt), \
31 struct gp8psk_fe_state
{
32 struct dvb_frontend fe
;
34 const struct gp8psk_fe_ops
*ops
;
38 unsigned long next_status_check
;
39 unsigned long status_check_interval
;
42 static int gp8psk_tuned_to_DCII(struct dvb_frontend
*fe
)
44 struct gp8psk_fe_state
*st
= fe
->demodulator_priv
;
47 st
->ops
->in(st
->priv
, GET_8PSK_CONFIG
, 0, 0, &status
, 1);
48 return status
& bmDCtuned
;
51 static int gp8psk_set_tuner_mode(struct dvb_frontend
*fe
, int mode
)
53 struct gp8psk_fe_state
*st
= fe
->demodulator_priv
;
55 return st
->ops
->out(st
->priv
, SET_8PSK_CONFIG
, mode
, 0, NULL
, 0);
58 static int gp8psk_fe_update_status(struct gp8psk_fe_state
*st
)
61 if (time_after(jiffies
,st
->next_status_check
)) {
62 st
->ops
->in(st
->priv
, GET_SIGNAL_LOCK
, 0, 0, &st
->lock
, 1);
63 st
->ops
->in(st
->priv
, GET_SIGNAL_STRENGTH
, 0, 0, buf
, 6);
64 st
->snr
= (buf
[1]) << 8 | buf
[0];
65 st
->next_status_check
= jiffies
+ (st
->status_check_interval
*HZ
)/1000;
70 static int gp8psk_fe_read_status(struct dvb_frontend
*fe
,
71 enum fe_status
*status
)
73 struct gp8psk_fe_state
*st
= fe
->demodulator_priv
;
74 gp8psk_fe_update_status(st
);
77 *status
= FE_HAS_LOCK
| FE_HAS_SYNC
| FE_HAS_VITERBI
| FE_HAS_SIGNAL
| FE_HAS_CARRIER
;
81 if (*status
& FE_HAS_LOCK
)
82 st
->status_check_interval
= 1000;
84 st
->status_check_interval
= 100;
88 /* not supported by this Frontend */
89 static int gp8psk_fe_read_ber(struct dvb_frontend
* fe
, u32
*ber
)
96 /* not supported by this Frontend */
97 static int gp8psk_fe_read_unc_blocks(struct dvb_frontend
* fe
, u32
*unc
)
104 static int gp8psk_fe_read_snr(struct dvb_frontend
* fe
, u16
*snr
)
106 struct gp8psk_fe_state
*st
= fe
->demodulator_priv
;
107 gp8psk_fe_update_status(st
);
108 /* snr is reported in dBu*256 */
113 static int gp8psk_fe_read_signal_strength(struct dvb_frontend
* fe
, u16
*strength
)
115 struct gp8psk_fe_state
*st
= fe
->demodulator_priv
;
116 gp8psk_fe_update_status(st
);
117 /* snr is reported in dBu*256 */
118 /* snr / 38.4 ~= 100% strength */
119 /* snr * 17 returns 100% strength as 65535 */
123 *strength
= (st
->snr
<< 4) + st
->snr
; /* snr*17 */
127 static int gp8psk_fe_get_tune_settings(struct dvb_frontend
* fe
, struct dvb_frontend_tune_settings
*tune
)
129 tune
->min_delay_ms
= 800;
133 static int gp8psk_fe_set_frontend(struct dvb_frontend
*fe
)
135 struct gp8psk_fe_state
*st
= fe
->demodulator_priv
;
136 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
138 u32 freq
= c
->frequency
* 1000;
140 dprintk("%s()\n", __func__
);
142 cmd
[4] = freq
& 0xff;
143 cmd
[5] = (freq
>> 8) & 0xff;
144 cmd
[6] = (freq
>> 16) & 0xff;
145 cmd
[7] = (freq
>> 24) & 0xff;
147 /* 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
;
151 switch (c
->delivery_system
) {
153 if (c
->modulation
!= QPSK
) {
154 dprintk("%s: unsupported modulation selected (%d)\n",
155 __func__
, c
->modulation
);
158 c
->fec_inner
= FEC_AUTO
;
160 case SYS_DVBS2
: /* kept for backwards compatibility */
161 dprintk("%s: DVB-S2 delivery system selected\n", __func__
);
164 dprintk("%s: Turbo-FEC delivery system selected\n", __func__
);
168 dprintk("%s: unsupported delivery system selected (%d)\n",
169 __func__
, c
->delivery_system
);
173 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
) {
180 if (gp8psk_tuned_to_DCII(fe
))
181 st
->ops
->reload(st
->priv
);
182 switch (c
->fec_inner
) {
198 if (c
->delivery_system
== SYS_TURBO
)
199 cmd
[8] = ADV_MOD_TURBO_QPSK
;
201 cmd
[8] = ADV_MOD_DVB_QPSK
;
203 case PSK_8
: /* PSK_8 is for compatibility with DN */
204 cmd
[8] = ADV_MOD_TURBO_8PSK
;
205 switch (c
->fec_inner
) {
220 case QAM_16
: /* QAM_16 is for compatibility with DN */
221 cmd
[8] = ADV_MOD_TURBO_16QAM
;
224 default: /* Unknown modulation */
225 dprintk("%s: unsupported modulation selected (%d)\n",
226 __func__
, c
->modulation
);
231 gp8psk_set_tuner_mode(fe
, 0);
232 st
->ops
->out(st
->priv
, TUNE_8PSK
, 0, 0, cmd
, 10);
235 st
->next_status_check
= jiffies
;
236 st
->status_check_interval
= 200;
241 static int gp8psk_fe_send_diseqc_msg (struct dvb_frontend
* fe
,
242 struct dvb_diseqc_master_cmd
*m
)
244 struct gp8psk_fe_state
*st
= fe
->demodulator_priv
;
246 dprintk("%s\n", __func__
);
248 if (st
->ops
->out(st
->priv
, SEND_DISEQC_COMMAND
, m
->msg
[0], 0,
249 m
->msg
, m
->msg_len
)) {
255 static int gp8psk_fe_send_diseqc_burst(struct dvb_frontend
*fe
,
256 enum fe_sec_mini_cmd burst
)
258 struct gp8psk_fe_state
*st
= fe
->demodulator_priv
;
261 dprintk("%s\n", __func__
);
263 /* These commands are certainly wrong */
264 cmd
= (burst
== SEC_MINI_A
) ? 0x00 : 0x01;
266 if (st
->ops
->out(st
->priv
, SEND_DISEQC_COMMAND
, cmd
, 0,
273 static int gp8psk_fe_set_tone(struct dvb_frontend
*fe
,
274 enum fe_sec_tone_mode tone
)
276 struct gp8psk_fe_state
*st
= fe
->demodulator_priv
;
278 if (st
->ops
->out(st
->priv
, SET_22KHZ_TONE
,
279 (tone
== SEC_TONE_ON
), 0, NULL
, 0)) {
285 static int gp8psk_fe_set_voltage(struct dvb_frontend
*fe
,
286 enum fe_sec_voltage voltage
)
288 struct gp8psk_fe_state
*st
= fe
->demodulator_priv
;
290 if (st
->ops
->out(st
->priv
, SET_LNB_VOLTAGE
,
291 voltage
== SEC_VOLTAGE_18
, 0, NULL
, 0)) {
297 static int gp8psk_fe_enable_high_lnb_voltage(struct dvb_frontend
* fe
, long onoff
)
299 struct gp8psk_fe_state
*st
= fe
->demodulator_priv
;
301 return st
->ops
->out(st
->priv
, USE_EXTRA_VOLT
, onoff
, 0, NULL
, 0);
304 static int gp8psk_fe_send_legacy_dish_cmd (struct dvb_frontend
* fe
, unsigned long sw_cmd
)
306 struct gp8psk_fe_state
*st
= fe
->demodulator_priv
;
307 u8 cmd
= sw_cmd
& 0x7f;
309 if (st
->ops
->out(st
->priv
, SET_DN_SWITCH
, cmd
, 0, NULL
, 0))
312 if (st
->ops
->out(st
->priv
, SET_LNB_VOLTAGE
, !!(sw_cmd
& 0x80),
319 static void gp8psk_fe_release(struct dvb_frontend
* fe
)
321 struct gp8psk_fe_state
*st
= fe
->demodulator_priv
;
326 static const struct dvb_frontend_ops gp8psk_fe_ops
;
328 struct dvb_frontend
*gp8psk_fe_attach(const struct gp8psk_fe_ops
*ops
,
329 void *priv
, bool is_rev1
)
331 struct gp8psk_fe_state
*st
;
333 if (!ops
|| !ops
->in
|| !ops
->out
|| !ops
->reload
) {
334 pr_err("Error! gp8psk-fe ops not defined.\n");
338 st
= kzalloc(sizeof(struct gp8psk_fe_state
), GFP_KERNEL
);
342 memcpy(&st
->fe
.ops
, &gp8psk_fe_ops
, sizeof(struct dvb_frontend_ops
));
343 st
->fe
.demodulator_priv
= st
;
346 st
->is_rev1
= is_rev1
;
348 pr_info("Frontend %sattached\n", is_rev1
? "revision 1 " : "");
352 EXPORT_SYMBOL_GPL(gp8psk_fe_attach
);
354 static const struct dvb_frontend_ops gp8psk_fe_ops
= {
355 .delsys
= { SYS_DVBS
},
357 .name
= "Genpix DVB-S",
358 .frequency_min
= 800000,
359 .frequency_max
= 2250000,
360 .frequency_stepsize
= 100,
361 .symbol_rate_min
= 1000000,
362 .symbol_rate_max
= 45000000,
363 .symbol_rate_tolerance
= 500, /* ppm */
364 .caps
= FE_CAN_INVERSION_AUTO
|
365 FE_CAN_FEC_1_2
| FE_CAN_FEC_2_3
| FE_CAN_FEC_3_4
|
366 FE_CAN_FEC_5_6
| FE_CAN_FEC_7_8
| FE_CAN_FEC_AUTO
|
368 * FE_CAN_QAM_16 is for compatibility
369 * (Myth incorrectly detects Turbo-QPSK as plain QAM-16)
371 FE_CAN_QPSK
| FE_CAN_QAM_16
| FE_CAN_TURBO_FEC
374 .release
= gp8psk_fe_release
,
379 .set_frontend
= gp8psk_fe_set_frontend
,
381 .get_tune_settings
= gp8psk_fe_get_tune_settings
,
383 .read_status
= gp8psk_fe_read_status
,
384 .read_ber
= gp8psk_fe_read_ber
,
385 .read_signal_strength
= gp8psk_fe_read_signal_strength
,
386 .read_snr
= gp8psk_fe_read_snr
,
387 .read_ucblocks
= gp8psk_fe_read_unc_blocks
,
389 .diseqc_send_master_cmd
= gp8psk_fe_send_diseqc_msg
,
390 .diseqc_send_burst
= gp8psk_fe_send_diseqc_burst
,
391 .set_tone
= gp8psk_fe_set_tone
,
392 .set_voltage
= gp8psk_fe_set_voltage
,
393 .dishnetwork_send_legacy_command
= gp8psk_fe_send_legacy_dish_cmd
,
394 .enable_high_lnb_voltage
= gp8psk_fe_enable_high_lnb_voltage
397 MODULE_AUTHOR("Alan Nisota <alannisota@gamil.com>");
398 MODULE_DESCRIPTION("Frontend Driver for Genpix DVB-S");
399 MODULE_VERSION("1.1");
400 MODULE_LICENSE("GPL");