13a137f81SMauro Carvalho Chehab // SPDX-License-Identifier: GPL-2.0-or-later
23a137f81SMauro Carvalho Chehab /*
33a137f81SMauro Carvalho Chehab * Driver for Dummy Frontend
43a137f81SMauro Carvalho Chehab *
53a137f81SMauro Carvalho Chehab * Written by Emard <emard@softhome.net>
63a137f81SMauro Carvalho Chehab */
73a137f81SMauro Carvalho Chehab
83a137f81SMauro Carvalho Chehab #include <linux/module.h>
93a137f81SMauro Carvalho Chehab #include <linux/init.h>
103a137f81SMauro Carvalho Chehab #include <linux/string.h>
113a137f81SMauro Carvalho Chehab #include <linux/slab.h>
123a137f81SMauro Carvalho Chehab
133a137f81SMauro Carvalho Chehab #include <media/dvb_frontend.h>
1494ab24a2SMauro Carvalho Chehab #include "ddbridge-dummy-fe.h"
153a137f81SMauro Carvalho Chehab
1694ab24a2SMauro Carvalho Chehab struct ddbridge_dummy_fe_state {
173a137f81SMauro Carvalho Chehab struct dvb_frontend frontend;
183a137f81SMauro Carvalho Chehab };
193a137f81SMauro Carvalho Chehab
ddbridge_dummy_fe_read_status(struct dvb_frontend * fe,enum fe_status * status)2094ab24a2SMauro Carvalho Chehab static int ddbridge_dummy_fe_read_status(struct dvb_frontend *fe,
213a137f81SMauro Carvalho Chehab enum fe_status *status)
223a137f81SMauro Carvalho Chehab {
233a137f81SMauro Carvalho Chehab *status = FE_HAS_SIGNAL
243a137f81SMauro Carvalho Chehab | FE_HAS_CARRIER
253a137f81SMauro Carvalho Chehab | FE_HAS_VITERBI
263a137f81SMauro Carvalho Chehab | FE_HAS_SYNC
273a137f81SMauro Carvalho Chehab | FE_HAS_LOCK;
283a137f81SMauro Carvalho Chehab
293a137f81SMauro Carvalho Chehab return 0;
303a137f81SMauro Carvalho Chehab }
313a137f81SMauro Carvalho Chehab
ddbridge_dummy_fe_read_ber(struct dvb_frontend * fe,u32 * ber)3294ab24a2SMauro Carvalho Chehab static int ddbridge_dummy_fe_read_ber(struct dvb_frontend *fe, u32 *ber)
333a137f81SMauro Carvalho Chehab {
343a137f81SMauro Carvalho Chehab *ber = 0;
353a137f81SMauro Carvalho Chehab return 0;
363a137f81SMauro Carvalho Chehab }
373a137f81SMauro Carvalho Chehab
ddbridge_dummy_fe_read_signal_strength(struct dvb_frontend * fe,u16 * strength)3894ab24a2SMauro Carvalho Chehab static int ddbridge_dummy_fe_read_signal_strength(struct dvb_frontend *fe,
393a137f81SMauro Carvalho Chehab u16 *strength)
403a137f81SMauro Carvalho Chehab {
413a137f81SMauro Carvalho Chehab *strength = 0;
423a137f81SMauro Carvalho Chehab return 0;
433a137f81SMauro Carvalho Chehab }
443a137f81SMauro Carvalho Chehab
ddbridge_dummy_fe_read_snr(struct dvb_frontend * fe,u16 * snr)4594ab24a2SMauro Carvalho Chehab static int ddbridge_dummy_fe_read_snr(struct dvb_frontend *fe, u16 *snr)
463a137f81SMauro Carvalho Chehab {
473a137f81SMauro Carvalho Chehab *snr = 0;
483a137f81SMauro Carvalho Chehab return 0;
493a137f81SMauro Carvalho Chehab }
503a137f81SMauro Carvalho Chehab
ddbridge_dummy_fe_read_ucblocks(struct dvb_frontend * fe,u32 * ucblocks)5194ab24a2SMauro Carvalho Chehab static int ddbridge_dummy_fe_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks)
523a137f81SMauro Carvalho Chehab {
533a137f81SMauro Carvalho Chehab *ucblocks = 0;
543a137f81SMauro Carvalho Chehab return 0;
553a137f81SMauro Carvalho Chehab }
563a137f81SMauro Carvalho Chehab
573a137f81SMauro Carvalho Chehab /*
583a137f81SMauro Carvalho Chehab * Should only be implemented if it actually reads something from the hardware.
593a137f81SMauro Carvalho Chehab * Also, it should check for the locks, in order to avoid report wrong data
603a137f81SMauro Carvalho Chehab * to userspace.
613a137f81SMauro Carvalho Chehab */
ddbridge_dummy_fe_get_frontend(struct dvb_frontend * fe,struct dtv_frontend_properties * p)6294ab24a2SMauro Carvalho Chehab static int ddbridge_dummy_fe_get_frontend(struct dvb_frontend *fe,
633a137f81SMauro Carvalho Chehab struct dtv_frontend_properties *p)
643a137f81SMauro Carvalho Chehab {
653a137f81SMauro Carvalho Chehab return 0;
663a137f81SMauro Carvalho Chehab }
673a137f81SMauro Carvalho Chehab
ddbridge_dummy_fe_set_frontend(struct dvb_frontend * fe)6894ab24a2SMauro Carvalho Chehab static int ddbridge_dummy_fe_set_frontend(struct dvb_frontend *fe)
693a137f81SMauro Carvalho Chehab {
703a137f81SMauro Carvalho Chehab if (fe->ops.tuner_ops.set_params) {
713a137f81SMauro Carvalho Chehab fe->ops.tuner_ops.set_params(fe);
723a137f81SMauro Carvalho Chehab if (fe->ops.i2c_gate_ctrl)
733a137f81SMauro Carvalho Chehab fe->ops.i2c_gate_ctrl(fe, 0);
743a137f81SMauro Carvalho Chehab }
753a137f81SMauro Carvalho Chehab
763a137f81SMauro Carvalho Chehab return 0;
773a137f81SMauro Carvalho Chehab }
783a137f81SMauro Carvalho Chehab
ddbridge_dummy_fe_sleep(struct dvb_frontend * fe)7994ab24a2SMauro Carvalho Chehab static int ddbridge_dummy_fe_sleep(struct dvb_frontend *fe)
803a137f81SMauro Carvalho Chehab {
813a137f81SMauro Carvalho Chehab return 0;
823a137f81SMauro Carvalho Chehab }
833a137f81SMauro Carvalho Chehab
ddbridge_dummy_fe_init(struct dvb_frontend * fe)8494ab24a2SMauro Carvalho Chehab static int ddbridge_dummy_fe_init(struct dvb_frontend *fe)
853a137f81SMauro Carvalho Chehab {
863a137f81SMauro Carvalho Chehab return 0;
873a137f81SMauro Carvalho Chehab }
883a137f81SMauro Carvalho Chehab
ddbridge_dummy_fe_release(struct dvb_frontend * fe)8994ab24a2SMauro Carvalho Chehab static void ddbridge_dummy_fe_release(struct dvb_frontend *fe)
903a137f81SMauro Carvalho Chehab {
9194ab24a2SMauro Carvalho Chehab struct ddbridge_dummy_fe_state *state = fe->demodulator_priv;
923a137f81SMauro Carvalho Chehab
933a137f81SMauro Carvalho Chehab kfree(state);
943a137f81SMauro Carvalho Chehab }
953a137f81SMauro Carvalho Chehab
9694ab24a2SMauro Carvalho Chehab static const struct dvb_frontend_ops ddbridge_dummy_fe_qam_ops;
973a137f81SMauro Carvalho Chehab
ddbridge_dummy_fe_qam_attach(void)9894ab24a2SMauro Carvalho Chehab struct dvb_frontend *ddbridge_dummy_fe_qam_attach(void)
993a137f81SMauro Carvalho Chehab {
10094ab24a2SMauro Carvalho Chehab struct ddbridge_dummy_fe_state *state = NULL;
1013a137f81SMauro Carvalho Chehab
1023a137f81SMauro Carvalho Chehab /* allocate memory for the internal state */
10394ab24a2SMauro Carvalho Chehab state = kzalloc(sizeof(struct ddbridge_dummy_fe_state), GFP_KERNEL);
1043a137f81SMauro Carvalho Chehab if (!state)
1053a137f81SMauro Carvalho Chehab return NULL;
1063a137f81SMauro Carvalho Chehab
1073a137f81SMauro Carvalho Chehab /* create dvb_frontend */
1083a137f81SMauro Carvalho Chehab memcpy(&state->frontend.ops,
10994ab24a2SMauro Carvalho Chehab &ddbridge_dummy_fe_qam_ops,
1103a137f81SMauro Carvalho Chehab sizeof(struct dvb_frontend_ops));
1113a137f81SMauro Carvalho Chehab
1123a137f81SMauro Carvalho Chehab state->frontend.demodulator_priv = state;
1133a137f81SMauro Carvalho Chehab return &state->frontend;
1143a137f81SMauro Carvalho Chehab }
115*86495af1SGreg Kroah-Hartman EXPORT_SYMBOL_GPL(ddbridge_dummy_fe_qam_attach);
1163a137f81SMauro Carvalho Chehab
11794ab24a2SMauro Carvalho Chehab static const struct dvb_frontend_ops ddbridge_dummy_fe_qam_ops = {
1183a137f81SMauro Carvalho Chehab .delsys = { SYS_DVBC_ANNEX_A },
1193a137f81SMauro Carvalho Chehab .info = {
12094ab24a2SMauro Carvalho Chehab .name = "ddbridge dummy DVB-C",
1213a137f81SMauro Carvalho Chehab .frequency_min_hz = 51 * MHz,
1223a137f81SMauro Carvalho Chehab .frequency_max_hz = 858 * MHz,
1233a137f81SMauro Carvalho Chehab .frequency_stepsize_hz = 62500,
1243a137f81SMauro Carvalho Chehab /* symbol_rate_min: SACLK/64 == (XIN/2)/64 */
1253a137f81SMauro Carvalho Chehab .symbol_rate_min = (57840000 / 2) / 64,
1263a137f81SMauro Carvalho Chehab .symbol_rate_max = (57840000 / 2) / 4, /* SACLK/4 */
1273a137f81SMauro Carvalho Chehab .caps = FE_CAN_QAM_16 |
1283a137f81SMauro Carvalho Chehab FE_CAN_QAM_32 |
1293a137f81SMauro Carvalho Chehab FE_CAN_QAM_64 |
1303a137f81SMauro Carvalho Chehab FE_CAN_QAM_128 |
1313a137f81SMauro Carvalho Chehab FE_CAN_QAM_256 |
1323a137f81SMauro Carvalho Chehab FE_CAN_FEC_AUTO |
1333a137f81SMauro Carvalho Chehab FE_CAN_INVERSION_AUTO
1343a137f81SMauro Carvalho Chehab },
1353a137f81SMauro Carvalho Chehab
13694ab24a2SMauro Carvalho Chehab .release = ddbridge_dummy_fe_release,
1373a137f81SMauro Carvalho Chehab
13894ab24a2SMauro Carvalho Chehab .init = ddbridge_dummy_fe_init,
13994ab24a2SMauro Carvalho Chehab .sleep = ddbridge_dummy_fe_sleep,
1403a137f81SMauro Carvalho Chehab
14194ab24a2SMauro Carvalho Chehab .set_frontend = ddbridge_dummy_fe_set_frontend,
14294ab24a2SMauro Carvalho Chehab .get_frontend = ddbridge_dummy_fe_get_frontend,
1433a137f81SMauro Carvalho Chehab
14494ab24a2SMauro Carvalho Chehab .read_status = ddbridge_dummy_fe_read_status,
14594ab24a2SMauro Carvalho Chehab .read_ber = ddbridge_dummy_fe_read_ber,
14694ab24a2SMauro Carvalho Chehab .read_signal_strength = ddbridge_dummy_fe_read_signal_strength,
14794ab24a2SMauro Carvalho Chehab .read_snr = ddbridge_dummy_fe_read_snr,
14894ab24a2SMauro Carvalho Chehab .read_ucblocks = ddbridge_dummy_fe_read_ucblocks,
1493a137f81SMauro Carvalho Chehab };
1503a137f81SMauro Carvalho Chehab
15194ab24a2SMauro Carvalho Chehab MODULE_DESCRIPTION("ddbridge dummy Frontend");
1523a137f81SMauro Carvalho Chehab MODULE_AUTHOR("Emard");
1533a137f81SMauro Carvalho Chehab MODULE_LICENSE("GPL");
154