162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * The Virtual DTV test driver serves as a reference DVB driver and helps
462306a36Sopenharmony_ci * validate the existing APIs in the media subsystem. It can also aid
562306a36Sopenharmony_ci * developers working on userspace applications.
662306a36Sopenharmony_ci *
762306a36Sopenharmony_ci * Copyright (C) 2020 Daniel W. S. Almeida
862306a36Sopenharmony_ci * Based on the example driver written by Emard <emard@softhome.net>
962306a36Sopenharmony_ci */
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ci#ifndef VIDTV_DEMOD_H
1262306a36Sopenharmony_ci#define VIDTV_DEMOD_H
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_ci#include <linux/dvb/frontend.h>
1562306a36Sopenharmony_ci
1662306a36Sopenharmony_ci#include <media/dvb_frontend.h>
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_ci/**
1962306a36Sopenharmony_ci * struct vidtv_demod_cnr_to_qual_s - Map CNR values to a given combination of
2062306a36Sopenharmony_ci * modulation and fec_inner
2162306a36Sopenharmony_ci * @modulation: see enum fe_modulation
2262306a36Sopenharmony_ci * @fec: see enum fe_fec_rate
2362306a36Sopenharmony_ci * @cnr_ok: S/N threshold to consider the signal as OK. Below that, there's
2462306a36Sopenharmony_ci *          a chance of losing sync.
2562306a36Sopenharmony_ci * @cnr_good: S/N threshold to consider the signal strong.
2662306a36Sopenharmony_ci *
2762306a36Sopenharmony_ci * This struct matches values for 'good' and 'ok' CNRs given the combination
2862306a36Sopenharmony_ci * of modulation and fec_inner in use. We might simulate some noise if the
2962306a36Sopenharmony_ci * signal quality is not too good.
3062306a36Sopenharmony_ci *
3162306a36Sopenharmony_ci * The values were taken from libdvbv5.
3262306a36Sopenharmony_ci */
3362306a36Sopenharmony_cistruct vidtv_demod_cnr_to_qual_s {
3462306a36Sopenharmony_ci	u32 modulation;
3562306a36Sopenharmony_ci	u32 fec;
3662306a36Sopenharmony_ci	u32 cnr_ok;
3762306a36Sopenharmony_ci	u32 cnr_good;
3862306a36Sopenharmony_ci};
3962306a36Sopenharmony_ci
4062306a36Sopenharmony_ci/**
4162306a36Sopenharmony_ci * struct vidtv_demod_config - Configuration used to init the demod
4262306a36Sopenharmony_ci * @drop_tslock_prob_on_low_snr: probability of losing the lock due to low snr
4362306a36Sopenharmony_ci * @recover_tslock_prob_on_good_snr: probability of recovering when the signal
4462306a36Sopenharmony_ci * improves
4562306a36Sopenharmony_ci *
4662306a36Sopenharmony_ci * The configuration used to init the demodulator module, usually filled
4762306a36Sopenharmony_ci * by a bridge driver. For vidtv, this is filled by vidtv_bridge before the
4862306a36Sopenharmony_ci * demodulator module is probed.
4962306a36Sopenharmony_ci */
5062306a36Sopenharmony_cistruct vidtv_demod_config {
5162306a36Sopenharmony_ci	u8 drop_tslock_prob_on_low_snr;
5262306a36Sopenharmony_ci	u8 recover_tslock_prob_on_good_snr;
5362306a36Sopenharmony_ci};
5462306a36Sopenharmony_ci
5562306a36Sopenharmony_ci/**
5662306a36Sopenharmony_ci * struct vidtv_demod_state - The demodulator state
5762306a36Sopenharmony_ci * @frontend: The frontend structure allocated by the demod.
5862306a36Sopenharmony_ci * @config: The config used to init the demod.
5962306a36Sopenharmony_ci * @status: the demod status.
6062306a36Sopenharmony_ci * @tuner_cnr: current S/N ratio for the signal carrier
6162306a36Sopenharmony_ci */
6262306a36Sopenharmony_cistruct vidtv_demod_state {
6362306a36Sopenharmony_ci	struct dvb_frontend frontend;
6462306a36Sopenharmony_ci	struct vidtv_demod_config config;
6562306a36Sopenharmony_ci	enum fe_status status;
6662306a36Sopenharmony_ci	u16 tuner_cnr;
6762306a36Sopenharmony_ci};
6862306a36Sopenharmony_ci#endif // VIDTV_DEMOD_H
69