1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  * The Virtual DTV test driver serves as a reference DVB driver and helps
4  * validate the existing APIs in the media subsystem. It can also aid
5  * developers working on userspace applications.
6  *
7  * Copyright (C) 2020 Daniel W. S. Almeida
8  * Based on the example driver written by Emard <emard@softhome.net>
9  */
10 
11 #ifndef VIDTV_DEMOD_H
12 #define VIDTV_DEMOD_H
13 
14 #include <linux/dvb/frontend.h>
15 
16 #include <media/dvb_frontend.h>
17 
18 /**
19  * struct vidtv_demod_cnr_to_qual_s - Map CNR values to a given combination of
20  * modulation and fec_inner
21  * @modulation: see enum fe_modulation
22  * @fec: see enum fe_fec_rate
23  * @cnr_ok: S/N threshold to consider the signal as OK. Below that, there's
24  *          a chance of losing sync.
25  * @cnr_good: S/N threshold to consider the signal strong.
26  *
27  * This struct matches values for 'good' and 'ok' CNRs given the combination
28  * of modulation and fec_inner in use. We might simulate some noise if the
29  * signal quality is not too good.
30  *
31  * The values were taken from libdvbv5.
32  */
33 struct vidtv_demod_cnr_to_qual_s {
34 	u32 modulation;
35 	u32 fec;
36 	u32 cnr_ok;
37 	u32 cnr_good;
38 };
39 
40 /**
41  * struct vidtv_demod_config - Configuration used to init the demod
42  * @drop_tslock_prob_on_low_snr: probability of losing the lock due to low snr
43  * @recover_tslock_prob_on_good_snr: probability of recovering when the signal
44  * improves
45  *
46  * The configuration used to init the demodulator module, usually filled
47  * by a bridge driver. For vidtv, this is filled by vidtv_bridge before the
48  * demodulator module is probed.
49  */
50 struct vidtv_demod_config {
51 	u8 drop_tslock_prob_on_low_snr;
52 	u8 recover_tslock_prob_on_good_snr;
53 };
54 
55 /**
56  * struct vidtv_demod_state - The demodulator state
57  * @frontend: The frontend structure allocated by the demod.
58  * @config: The config used to init the demod.
59  * @status: the demod status.
60  * @tuner_cnr: current S/N ratio for the signal carrier
61  */
62 struct vidtv_demod_state {
63 	struct dvb_frontend frontend;
64 	struct vidtv_demod_config config;
65 	enum fe_status status;
66 	u16 tuner_cnr;
67 };
68 #endif // VIDTV_DEMOD_H
69