1 // SPDX-License-Identifier: GPL-2.0-only
3 * Frontend driver for the GENPIX 8pks/qpsk/DCII USB2.0 DVB-S module
5 * Copyright (C) 2006,2007 Alan Nisota (alannisota@gmail.com)
6 * Copyright (C) 2006,2007 Genpix Electronics (genpix@genpix-electronics.com)
8 * Thanks to GENPIX for the sample code used to implement this module.
10 * This module is based off the vp7045 and vp702x modules
13 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
15 #include "gp8psk-fe.h"
16 #include <media/dvb_frontend.h>
19 module_param(debug
, int, 0644);
20 MODULE_PARM_DESC(debug
, "Turn on/off debugging (default:off).");
22 #define dprintk(fmt, arg...) do { \
24 printk(KERN_DEBUG pr_fmt("%s: " fmt), \
28 struct gp8psk_fe_state
{
29 struct dvb_frontend fe
;
31 const struct gp8psk_fe_ops
*ops
;
35 unsigned long next_status_check
;
36 unsigned long status_check_interval
;
39 static int gp8psk_tuned_to_DCII(struct dvb_frontend
*fe
)
41 struct gp8psk_fe_state
*st
= fe
->demodulator_priv
;
44 st
->ops
->in(st
->priv
, GET_8PSK_CONFIG
, 0, 0, &status
, 1);
45 return status
& bmDCtuned
;
48 static int gp8psk_set_tuner_mode(struct dvb_frontend
*fe
, int mode
)
50 struct gp8psk_fe_state
*st
= fe
->demodulator_priv
;
52 return st
->ops
->out(st
->priv
, SET_8PSK_CONFIG
, mode
, 0, NULL
, 0);
55 static int gp8psk_fe_update_status(struct gp8psk_fe_state
*st
)
58 if (time_after(jiffies
,st
->next_status_check
)) {
59 st
->ops
->in(st
->priv
, GET_SIGNAL_LOCK
, 0, 0, &st
->lock
, 1);
60 st
->ops
->in(st
->priv
, GET_SIGNAL_STRENGTH
, 0, 0, buf
, 6);
61 st
->snr
= (buf
[1]) << 8 | buf
[0];
62 st
->next_status_check
= jiffies
+ (st
->status_check_interval
*HZ
)/1000;
67 static int gp8psk_fe_read_status(struct dvb_frontend
*fe
,
68 enum fe_status
*status
)
70 struct gp8psk_fe_state
*st
= fe
->demodulator_priv
;
71 gp8psk_fe_update_status(st
);
74 *status
= FE_HAS_LOCK
| FE_HAS_SYNC
| FE_HAS_VITERBI
| FE_HAS_SIGNAL
| FE_HAS_CARRIER
;
78 if (*status
& FE_HAS_LOCK
)
79 st
->status_check_interval
= 1000;
81 st
->status_check_interval
= 100;
85 /* not supported by this Frontend */
86 static int gp8psk_fe_read_ber(struct dvb_frontend
* fe
, u32
*ber
)
93 /* not supported by this Frontend */
94 static int gp8psk_fe_read_unc_blocks(struct dvb_frontend
* fe
, u32
*unc
)
101 static int gp8psk_fe_read_snr(struct dvb_frontend
* fe
, u16
*snr
)
103 struct gp8psk_fe_state
*st
= fe
->demodulator_priv
;
104 gp8psk_fe_update_status(st
);
105 /* snr is reported in dBu*256 */
110 static int gp8psk_fe_read_signal_strength(struct dvb_frontend
* fe
, u16
*strength
)
112 struct gp8psk_fe_state
*st
= fe
->demodulator_priv
;
113 gp8psk_fe_update_status(st
);
114 /* snr is reported in dBu*256 */
115 /* snr / 38.4 ~= 100% strength */
116 /* snr * 17 returns 100% strength as 65535 */
120 *strength
= (st
->snr
<< 4) + st
->snr
; /* snr*17 */
124 static int gp8psk_fe_get_tune_settings(struct dvb_frontend
* fe
, struct dvb_frontend_tune_settings
*tune
)
126 tune
->min_delay_ms
= 800;
130 static int gp8psk_fe_set_frontend(struct dvb_frontend
*fe
)
132 struct gp8psk_fe_state
*st
= fe
->demodulator_priv
;
133 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
135 u32 freq
= c
->frequency
* 1000;
137 dprintk("%s()\n", __func__
);
139 cmd
[4] = freq
& 0xff;
140 cmd
[5] = (freq
>> 8) & 0xff;
141 cmd
[6] = (freq
>> 16) & 0xff;
142 cmd
[7] = (freq
>> 24) & 0xff;
144 /* backwards compatibility: DVB-S + 8-PSK were used for Turbo-FEC */
145 if (c
->delivery_system
== SYS_DVBS
&& c
->modulation
== PSK_8
)
146 c
->delivery_system
= SYS_TURBO
;
148 switch (c
->delivery_system
) {
150 if (c
->modulation
!= QPSK
) {
151 dprintk("%s: unsupported modulation selected (%d)\n",
152 __func__
, c
->modulation
);
155 c
->fec_inner
= FEC_AUTO
;
157 case SYS_DVBS2
: /* kept for backwards compatibility */
158 dprintk("%s: DVB-S2 delivery system selected\n", __func__
);
161 dprintk("%s: Turbo-FEC delivery system selected\n", __func__
);
165 dprintk("%s: unsupported delivery system selected (%d)\n",
166 __func__
, c
->delivery_system
);
170 cmd
[0] = c
->symbol_rate
& 0xff;
171 cmd
[1] = (c
->symbol_rate
>> 8) & 0xff;
172 cmd
[2] = (c
->symbol_rate
>> 16) & 0xff;
173 cmd
[3] = (c
->symbol_rate
>> 24) & 0xff;
174 switch (c
->modulation
) {
177 if (gp8psk_tuned_to_DCII(fe
))
178 st
->ops
->reload(st
->priv
);
179 switch (c
->fec_inner
) {
195 if (c
->delivery_system
== SYS_TURBO
)
196 cmd
[8] = ADV_MOD_TURBO_QPSK
;
198 cmd
[8] = ADV_MOD_DVB_QPSK
;
200 case PSK_8
: /* PSK_8 is for compatibility with DN */
201 cmd
[8] = ADV_MOD_TURBO_8PSK
;
202 switch (c
->fec_inner
) {
217 case QAM_16
: /* QAM_16 is for compatibility with DN */
218 cmd
[8] = ADV_MOD_TURBO_16QAM
;
221 default: /* Unknown modulation */
222 dprintk("%s: unsupported modulation selected (%d)\n",
223 __func__
, c
->modulation
);
228 gp8psk_set_tuner_mode(fe
, 0);
229 st
->ops
->out(st
->priv
, TUNE_8PSK
, 0, 0, cmd
, 10);
232 st
->next_status_check
= jiffies
;
233 st
->status_check_interval
= 200;
238 static int gp8psk_fe_send_diseqc_msg (struct dvb_frontend
* fe
,
239 struct dvb_diseqc_master_cmd
*m
)
241 struct gp8psk_fe_state
*st
= fe
->demodulator_priv
;
243 dprintk("%s\n", __func__
);
245 if (st
->ops
->out(st
->priv
, SEND_DISEQC_COMMAND
, m
->msg
[0], 0,
246 m
->msg
, m
->msg_len
)) {
252 static int gp8psk_fe_send_diseqc_burst(struct dvb_frontend
*fe
,
253 enum fe_sec_mini_cmd burst
)
255 struct gp8psk_fe_state
*st
= fe
->demodulator_priv
;
258 dprintk("%s\n", __func__
);
260 /* These commands are certainly wrong */
261 cmd
= (burst
== SEC_MINI_A
) ? 0x00 : 0x01;
263 if (st
->ops
->out(st
->priv
, SEND_DISEQC_COMMAND
, cmd
, 0,
270 static int gp8psk_fe_set_tone(struct dvb_frontend
*fe
,
271 enum fe_sec_tone_mode tone
)
273 struct gp8psk_fe_state
*st
= fe
->demodulator_priv
;
275 if (st
->ops
->out(st
->priv
, SET_22KHZ_TONE
,
276 (tone
== SEC_TONE_ON
), 0, NULL
, 0)) {
282 static int gp8psk_fe_set_voltage(struct dvb_frontend
*fe
,
283 enum fe_sec_voltage voltage
)
285 struct gp8psk_fe_state
*st
= fe
->demodulator_priv
;
287 if (st
->ops
->out(st
->priv
, SET_LNB_VOLTAGE
,
288 voltage
== SEC_VOLTAGE_18
, 0, NULL
, 0)) {
294 static int gp8psk_fe_enable_high_lnb_voltage(struct dvb_frontend
* fe
, long onoff
)
296 struct gp8psk_fe_state
*st
= fe
->demodulator_priv
;
298 return st
->ops
->out(st
->priv
, USE_EXTRA_VOLT
, onoff
, 0, NULL
, 0);
301 static int gp8psk_fe_send_legacy_dish_cmd (struct dvb_frontend
* fe
, unsigned long sw_cmd
)
303 struct gp8psk_fe_state
*st
= fe
->demodulator_priv
;
304 u8 cmd
= sw_cmd
& 0x7f;
306 if (st
->ops
->out(st
->priv
, SET_DN_SWITCH
, cmd
, 0, NULL
, 0))
309 if (st
->ops
->out(st
->priv
, SET_LNB_VOLTAGE
, !!(sw_cmd
& 0x80),
316 static void gp8psk_fe_release(struct dvb_frontend
* fe
)
318 struct gp8psk_fe_state
*st
= fe
->demodulator_priv
;
323 static const struct dvb_frontend_ops gp8psk_fe_ops
;
325 struct dvb_frontend
*gp8psk_fe_attach(const struct gp8psk_fe_ops
*ops
,
326 void *priv
, bool is_rev1
)
328 struct gp8psk_fe_state
*st
;
330 if (!ops
|| !ops
->in
|| !ops
->out
|| !ops
->reload
) {
331 pr_err("Error! gp8psk-fe ops not defined.\n");
335 st
= kzalloc(sizeof(struct gp8psk_fe_state
), GFP_KERNEL
);
339 memcpy(&st
->fe
.ops
, &gp8psk_fe_ops
, sizeof(struct dvb_frontend_ops
));
340 st
->fe
.demodulator_priv
= st
;
343 st
->is_rev1
= is_rev1
;
345 pr_info("Frontend %sattached\n", is_rev1
? "revision 1 " : "");
349 EXPORT_SYMBOL_GPL(gp8psk_fe_attach
);
351 static const struct dvb_frontend_ops gp8psk_fe_ops
= {
352 .delsys
= { SYS_DVBS
},
354 .name
= "Genpix DVB-S",
355 .frequency_min_hz
= 800 * MHz
,
356 .frequency_max_hz
= 2250 * MHz
,
357 .frequency_stepsize_hz
= 100 * kHz
,
358 .symbol_rate_min
= 1000000,
359 .symbol_rate_max
= 45000000,
360 .symbol_rate_tolerance
= 500, /* ppm */
361 .caps
= FE_CAN_INVERSION_AUTO
|
362 FE_CAN_FEC_1_2
| FE_CAN_FEC_2_3
| FE_CAN_FEC_3_4
|
363 FE_CAN_FEC_5_6
| FE_CAN_FEC_7_8
| FE_CAN_FEC_AUTO
|
365 * FE_CAN_QAM_16 is for compatibility
366 * (Myth incorrectly detects Turbo-QPSK as plain QAM-16)
368 FE_CAN_QPSK
| FE_CAN_QAM_16
| FE_CAN_TURBO_FEC
371 .release
= gp8psk_fe_release
,
376 .set_frontend
= gp8psk_fe_set_frontend
,
378 .get_tune_settings
= gp8psk_fe_get_tune_settings
,
380 .read_status
= gp8psk_fe_read_status
,
381 .read_ber
= gp8psk_fe_read_ber
,
382 .read_signal_strength
= gp8psk_fe_read_signal_strength
,
383 .read_snr
= gp8psk_fe_read_snr
,
384 .read_ucblocks
= gp8psk_fe_read_unc_blocks
,
386 .diseqc_send_master_cmd
= gp8psk_fe_send_diseqc_msg
,
387 .diseqc_send_burst
= gp8psk_fe_send_diseqc_burst
,
388 .set_tone
= gp8psk_fe_set_tone
,
389 .set_voltage
= gp8psk_fe_set_voltage
,
390 .dishnetwork_send_legacy_command
= gp8psk_fe_send_legacy_dish_cmd
,
391 .enable_high_lnb_voltage
= gp8psk_fe_enable_high_lnb_voltage
394 MODULE_AUTHOR("Alan Nisota <alannisota@gamil.com>");
395 MODULE_DESCRIPTION("Frontend Driver for Genpix DVB-S");
396 MODULE_VERSION("1.1");
397 MODULE_LICENSE("GPL");