1 /*
2  *  Driver for Dummy Frontend
3  *
4  *  Written by Emard <emard@softhome.net>
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2 of the License, or
9  *  (at your option) any later version.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *
15  *  GNU General Public License for more details.
16  */
17 
18 #include <linux/module.h>
19 #include <linux/init.h>
20 #include <linux/string.h>
21 #include <linux/slab.h>
22 
23 #include "dvb_frontend.h"
24 #include "dvb_dummy_fe.h"
25 
26 
27 struct dvb_dummy_fe_state {
28 	struct dvb_frontend frontend;
29 };
30 
31 
32 static int dvb_dummy_fe_read_status(struct dvb_frontend *fe,
33 				    enum fe_status *status)
34 {
35 	*status = FE_HAS_SIGNAL
36 		| FE_HAS_CARRIER
37 		| FE_HAS_VITERBI
38 		| FE_HAS_SYNC
39 		| FE_HAS_LOCK;
40 
41 	return 0;
42 }
43 
44 static int dvb_dummy_fe_read_ber(struct dvb_frontend* fe, u32* ber)
45 {
46 	*ber = 0;
47 	return 0;
48 }
49 
50 static int dvb_dummy_fe_read_signal_strength(struct dvb_frontend* fe, u16* strength)
51 {
52 	*strength = 0;
53 	return 0;
54 }
55 
56 static int dvb_dummy_fe_read_snr(struct dvb_frontend* fe, u16* snr)
57 {
58 	*snr = 0;
59 	return 0;
60 }
61 
62 static int dvb_dummy_fe_read_ucblocks(struct dvb_frontend* fe, u32* ucblocks)
63 {
64 	*ucblocks = 0;
65 	return 0;
66 }
67 
68 /*
69  * Should only be implemented if it actually reads something from the hardware.
70  * Also, it should check for the locks, in order to avoid report wrong data
71  * to userspace.
72  */
73 static int dvb_dummy_fe_get_frontend(struct dvb_frontend *fe,
74 				     struct dtv_frontend_properties *p)
75 {
76 	return 0;
77 }
78 
79 static int dvb_dummy_fe_set_frontend(struct dvb_frontend *fe)
80 {
81 	if (fe->ops.tuner_ops.set_params) {
82 		fe->ops.tuner_ops.set_params(fe);
83 		if (fe->ops.i2c_gate_ctrl)
84 			fe->ops.i2c_gate_ctrl(fe, 0);
85 	}
86 
87 	return 0;
88 }
89 
90 static int dvb_dummy_fe_sleep(struct dvb_frontend* fe)
91 {
92 	return 0;
93 }
94 
95 static int dvb_dummy_fe_init(struct dvb_frontend* fe)
96 {
97 	return 0;
98 }
99 
100 static int dvb_dummy_fe_set_tone(struct dvb_frontend *fe,
101 				 enum fe_sec_tone_mode tone)
102 {
103 	return 0;
104 }
105 
106 static int dvb_dummy_fe_set_voltage(struct dvb_frontend *fe,
107 				    enum fe_sec_voltage voltage)
108 {
109 	return 0;
110 }
111 
112 static void dvb_dummy_fe_release(struct dvb_frontend* fe)
113 {
114 	struct dvb_dummy_fe_state* state = fe->demodulator_priv;
115 	kfree(state);
116 }
117 
118 static const struct dvb_frontend_ops dvb_dummy_fe_ofdm_ops;
119 
120 struct dvb_frontend* dvb_dummy_fe_ofdm_attach(void)
121 {
122 	struct dvb_dummy_fe_state* state = NULL;
123 
124 	/* allocate memory for the internal state */
125 	state = kzalloc(sizeof(struct dvb_dummy_fe_state), GFP_KERNEL);
126 	if (!state)
127 		return NULL;
128 
129 	/* create dvb_frontend */
130 	memcpy(&state->frontend.ops, &dvb_dummy_fe_ofdm_ops, sizeof(struct dvb_frontend_ops));
131 	state->frontend.demodulator_priv = state;
132 	return &state->frontend;
133 }
134 
135 static const struct dvb_frontend_ops dvb_dummy_fe_qpsk_ops;
136 
137 struct dvb_frontend *dvb_dummy_fe_qpsk_attach(void)
138 {
139 	struct dvb_dummy_fe_state* state = NULL;
140 
141 	/* allocate memory for the internal state */
142 	state = kzalloc(sizeof(struct dvb_dummy_fe_state), GFP_KERNEL);
143 	if (!state)
144 		return NULL;
145 
146 	/* create dvb_frontend */
147 	memcpy(&state->frontend.ops, &dvb_dummy_fe_qpsk_ops, sizeof(struct dvb_frontend_ops));
148 	state->frontend.demodulator_priv = state;
149 	return &state->frontend;
150 }
151 
152 static const struct dvb_frontend_ops dvb_dummy_fe_qam_ops;
153 
154 struct dvb_frontend *dvb_dummy_fe_qam_attach(void)
155 {
156 	struct dvb_dummy_fe_state* state = NULL;
157 
158 	/* allocate memory for the internal state */
159 	state = kzalloc(sizeof(struct dvb_dummy_fe_state), GFP_KERNEL);
160 	if (!state)
161 		return NULL;
162 
163 	/* create dvb_frontend */
164 	memcpy(&state->frontend.ops, &dvb_dummy_fe_qam_ops, sizeof(struct dvb_frontend_ops));
165 	state->frontend.demodulator_priv = state;
166 	return &state->frontend;
167 }
168 
169 static const struct dvb_frontend_ops dvb_dummy_fe_ofdm_ops = {
170 	.delsys = { SYS_DVBT },
171 	.info = {
172 		.name			= "Dummy DVB-T",
173 		.frequency_min		= 0,
174 		.frequency_max		= 863250000,
175 		.frequency_stepsize	= 62500,
176 		.caps = FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
177 				FE_CAN_FEC_4_5 | FE_CAN_FEC_5_6 | FE_CAN_FEC_6_7 |
178 				FE_CAN_FEC_7_8 | FE_CAN_FEC_8_9 | FE_CAN_FEC_AUTO |
179 				FE_CAN_QAM_16 | FE_CAN_QAM_64 | FE_CAN_QAM_AUTO |
180 				FE_CAN_TRANSMISSION_MODE_AUTO |
181 				FE_CAN_GUARD_INTERVAL_AUTO |
182 				FE_CAN_HIERARCHY_AUTO,
183 	},
184 
185 	.release = dvb_dummy_fe_release,
186 
187 	.init = dvb_dummy_fe_init,
188 	.sleep = dvb_dummy_fe_sleep,
189 
190 	.set_frontend = dvb_dummy_fe_set_frontend,
191 	.get_frontend = dvb_dummy_fe_get_frontend,
192 
193 	.read_status = dvb_dummy_fe_read_status,
194 	.read_ber = dvb_dummy_fe_read_ber,
195 	.read_signal_strength = dvb_dummy_fe_read_signal_strength,
196 	.read_snr = dvb_dummy_fe_read_snr,
197 	.read_ucblocks = dvb_dummy_fe_read_ucblocks,
198 };
199 
200 static const struct dvb_frontend_ops dvb_dummy_fe_qam_ops = {
201 	.delsys = { SYS_DVBC_ANNEX_A },
202 	.info = {
203 		.name			= "Dummy DVB-C",
204 		.frequency_stepsize	= 62500,
205 		.frequency_min		= 51000000,
206 		.frequency_max		= 858000000,
207 		.symbol_rate_min	= (57840000/2)/64,     /* SACLK/64 == (XIN/2)/64 */
208 		.symbol_rate_max	= (57840000/2)/4,      /* SACLK/4 */
209 		.caps = FE_CAN_QAM_16 | FE_CAN_QAM_32 | FE_CAN_QAM_64 |
210 			FE_CAN_QAM_128 | FE_CAN_QAM_256 |
211 			FE_CAN_FEC_AUTO | FE_CAN_INVERSION_AUTO
212 	},
213 
214 	.release = dvb_dummy_fe_release,
215 
216 	.init = dvb_dummy_fe_init,
217 	.sleep = dvb_dummy_fe_sleep,
218 
219 	.set_frontend = dvb_dummy_fe_set_frontend,
220 	.get_frontend = dvb_dummy_fe_get_frontend,
221 
222 	.read_status = dvb_dummy_fe_read_status,
223 	.read_ber = dvb_dummy_fe_read_ber,
224 	.read_signal_strength = dvb_dummy_fe_read_signal_strength,
225 	.read_snr = dvb_dummy_fe_read_snr,
226 	.read_ucblocks = dvb_dummy_fe_read_ucblocks,
227 };
228 
229 static const struct dvb_frontend_ops dvb_dummy_fe_qpsk_ops = {
230 	.delsys = { SYS_DVBS },
231 	.info = {
232 		.name			= "Dummy DVB-S",
233 		.frequency_min		= 950000,
234 		.frequency_max		= 2150000,
235 		.frequency_stepsize	= 250,           /* kHz for QPSK frontends */
236 		.frequency_tolerance	= 29500,
237 		.symbol_rate_min	= 1000000,
238 		.symbol_rate_max	= 45000000,
239 		.caps = FE_CAN_INVERSION_AUTO |
240 			FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
241 			FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO |
242 			FE_CAN_QPSK
243 	},
244 
245 	.release = dvb_dummy_fe_release,
246 
247 	.init = dvb_dummy_fe_init,
248 	.sleep = dvb_dummy_fe_sleep,
249 
250 	.set_frontend = dvb_dummy_fe_set_frontend,
251 	.get_frontend = dvb_dummy_fe_get_frontend,
252 
253 	.read_status = dvb_dummy_fe_read_status,
254 	.read_ber = dvb_dummy_fe_read_ber,
255 	.read_signal_strength = dvb_dummy_fe_read_signal_strength,
256 	.read_snr = dvb_dummy_fe_read_snr,
257 	.read_ucblocks = dvb_dummy_fe_read_ucblocks,
258 
259 	.set_voltage = dvb_dummy_fe_set_voltage,
260 	.set_tone = dvb_dummy_fe_set_tone,
261 };
262 
263 MODULE_DESCRIPTION("DVB DUMMY Frontend");
264 MODULE_AUTHOR("Emard");
265 MODULE_LICENSE("GPL");
266 
267 EXPORT_SYMBOL(dvb_dummy_fe_ofdm_attach);
268 EXPORT_SYMBOL(dvb_dummy_fe_qam_attach);
269 EXPORT_SYMBOL(dvb_dummy_fe_qpsk_attach);
270