1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  *  Driver for Dummy Frontend
4  *
5  *  Written by Emard <emard@softhome.net>
6  */
7 
8 #include <linux/module.h>
9 #include <linux/init.h>
10 #include <linux/string.h>
11 #include <linux/slab.h>
12 
13 #include <media/dvb_frontend.h>
14 #include "ddbridge-dummy-fe.h"
15 
16 struct ddbridge_dummy_fe_state {
17 	struct dvb_frontend frontend;
18 };
19 
20 static int ddbridge_dummy_fe_read_status(struct dvb_frontend *fe,
21 				    enum fe_status *status)
22 {
23 	*status = FE_HAS_SIGNAL
24 		| FE_HAS_CARRIER
25 		| FE_HAS_VITERBI
26 		| FE_HAS_SYNC
27 		| FE_HAS_LOCK;
28 
29 	return 0;
30 }
31 
32 static int ddbridge_dummy_fe_read_ber(struct dvb_frontend *fe, u32 *ber)
33 {
34 	*ber = 0;
35 	return 0;
36 }
37 
38 static int ddbridge_dummy_fe_read_signal_strength(struct dvb_frontend *fe,
39 					     u16 *strength)
40 {
41 	*strength = 0;
42 	return 0;
43 }
44 
45 static int ddbridge_dummy_fe_read_snr(struct dvb_frontend *fe, u16 *snr)
46 {
47 	*snr = 0;
48 	return 0;
49 }
50 
51 static int ddbridge_dummy_fe_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks)
52 {
53 	*ucblocks = 0;
54 	return 0;
55 }
56 
57 /*
58  * Should only be implemented if it actually reads something from the hardware.
59  * Also, it should check for the locks, in order to avoid report wrong data
60  * to userspace.
61  */
62 static int ddbridge_dummy_fe_get_frontend(struct dvb_frontend *fe,
63 				     struct dtv_frontend_properties *p)
64 {
65 	return 0;
66 }
67 
68 static int ddbridge_dummy_fe_set_frontend(struct dvb_frontend *fe)
69 {
70 	if (fe->ops.tuner_ops.set_params) {
71 		fe->ops.tuner_ops.set_params(fe);
72 		if (fe->ops.i2c_gate_ctrl)
73 			fe->ops.i2c_gate_ctrl(fe, 0);
74 	}
75 
76 	return 0;
77 }
78 
79 static int ddbridge_dummy_fe_sleep(struct dvb_frontend *fe)
80 {
81 	return 0;
82 }
83 
84 static int ddbridge_dummy_fe_init(struct dvb_frontend *fe)
85 {
86 	return 0;
87 }
88 
89 static void ddbridge_dummy_fe_release(struct dvb_frontend *fe)
90 {
91 	struct ddbridge_dummy_fe_state *state = fe->demodulator_priv;
92 
93 	kfree(state);
94 }
95 
96 static const struct dvb_frontend_ops ddbridge_dummy_fe_qam_ops;
97 
98 struct dvb_frontend *ddbridge_dummy_fe_qam_attach(void)
99 {
100 	struct ddbridge_dummy_fe_state *state = NULL;
101 
102 	/* allocate memory for the internal state */
103 	state = kzalloc(sizeof(struct ddbridge_dummy_fe_state), GFP_KERNEL);
104 	if (!state)
105 		return NULL;
106 
107 	/* create dvb_frontend */
108 	memcpy(&state->frontend.ops,
109 	       &ddbridge_dummy_fe_qam_ops,
110 	       sizeof(struct dvb_frontend_ops));
111 
112 	state->frontend.demodulator_priv = state;
113 	return &state->frontend;
114 }
115 EXPORT_SYMBOL_GPL(ddbridge_dummy_fe_qam_attach);
116 
117 static const struct dvb_frontend_ops ddbridge_dummy_fe_qam_ops = {
118 	.delsys = { SYS_DVBC_ANNEX_A },
119 	.info = {
120 		.name			= "ddbridge dummy DVB-C",
121 		.frequency_min_hz	=  51 * MHz,
122 		.frequency_max_hz	= 858 * MHz,
123 		.frequency_stepsize_hz	= 62500,
124 		/* symbol_rate_min: SACLK/64 == (XIN/2)/64 */
125 		.symbol_rate_min	= (57840000 / 2) / 64,
126 		.symbol_rate_max	= (57840000 / 2) / 4,   /* SACLK/4 */
127 		.caps = FE_CAN_QAM_16 |
128 			FE_CAN_QAM_32 |
129 			FE_CAN_QAM_64 |
130 			FE_CAN_QAM_128 |
131 			FE_CAN_QAM_256 |
132 			FE_CAN_FEC_AUTO |
133 			FE_CAN_INVERSION_AUTO
134 	},
135 
136 	.release = ddbridge_dummy_fe_release,
137 
138 	.init = ddbridge_dummy_fe_init,
139 	.sleep = ddbridge_dummy_fe_sleep,
140 
141 	.set_frontend = ddbridge_dummy_fe_set_frontend,
142 	.get_frontend = ddbridge_dummy_fe_get_frontend,
143 
144 	.read_status = ddbridge_dummy_fe_read_status,
145 	.read_ber = ddbridge_dummy_fe_read_ber,
146 	.read_signal_strength = ddbridge_dummy_fe_read_signal_strength,
147 	.read_snr = ddbridge_dummy_fe_read_snr,
148 	.read_ucblocks = ddbridge_dummy_fe_read_ucblocks,
149 };
150 
151 MODULE_DESCRIPTION("ddbridge dummy Frontend");
152 MODULE_AUTHOR("Emard");
153 MODULE_LICENSE("GPL");
154